#62842 closed enhancement (fixed)
PHPDoc of get_category() is misleading
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.8 | Priority: | normal |
| Severity: | normal | Version: | 4.4 |
| Component: | Taxonomy | Keywords: | has-patch |
| Focuses: | Cc: |
Description
Recently I stumbled upon the case that get_term() will return an instance of WP_Term while get_category() suggests it will just return an object. And when I wanted to add strict comparison I was hesitant.
// Results via wp shell from a german project: Allgemein => uncategorized
> get_category(1)
= WP_Term {#10541
+term_id: 1,
+name: "Allgemein",
+slug: "allgemein",
+term_group: 0,
+term_taxonomy_id: 1,
+taxonomy: "category",
+description: "",
+parent: 0,
+count: 50,
+filter: "raw",
+"cat_ID": 1,
+"category_count": 50,
+"category_description": "",
+"cat_name": "Allgemein",
+"category_nicename": "allgemein",
+"category_parent": 0,
}
> get_term(1,'category')
= WP_Term {#10553
+term_id: 1,
+name: "Allgemein",
+slug: "allgemein",
+term_group: 0,
+term_taxonomy_id: 1,
+taxonomy: "category",
+description: "",
+parent: 0,
+count: 50,
+filter: "raw",
}
First of all, I think we should fix the PHPDoc, and I will open a PR for that.
Additionally I want to spark the discussion to either add WPCS rules to discourage the use of the aliases or maybe just mark get_category() as deprecated in favor of get_term( $term, 'category' ).
Change History (9)
This ticket was mentioned in PR #8166 on WordPress/wordpress-develop by @apermo.
11 months ago
#1
- Keywords has-patch added
This ticket was mentioned in Slack in #core-coding-standards by apermo. View the logs.
11 months ago
#3
@
11 months ago
- Milestone changed from Awaiting Review to 6.8
- Owner set to audrasjb
- Status changed from new to reviewing
Hello, thanks for the proposal.
The suggested changes look good to me at a glance. Moving to milestone 6.8.
Maybe I'd rephrase a bit the explanation (see PR comments).
#4
@
11 months ago
I already applied your suggestion, and I threw the link into the coding standards channel.
#5
follow-up:
↓ 8
@
11 months ago
Additional question:
https://php.watch/versions/8.2/dynamic-properties-deprecated
Regarding the deprecation of dynamic properties, won't this backwards compatibility function throw a deprecation warning with 8.2?
@audrasjb commented on PR #8166:
11 months ago
#7
committed in https://core.trac.wordpress.org/changeset/59704
#8
in reply to:
↑ 5
@
11 months ago
Replying to apermo:
Additional question:
https://php.watch/versions/8.2/dynamic-properties-deprecated
Regarding the deprecation of dynamic properties, won't this backwards compatibility function throw a deprecation warning with 8.2?
Good point! Let's open a new specific ticket for this.
#9
@
11 months ago
@audrasjb I've opened https://core.trac.wordpress.org/ticket/62863, though I found that WP_Term already allows dynamic properties, though I do think that we can still improve on that. More in the other ticket.
Added more details that WP_Term will have additional backwards compatible aliases for the era before WP 4.4 and 2.3
Trac ticket: https://core.trac.wordpress.org/ticket/62842#ticket