Opened 10 years ago
Closed 10 years ago
#36227 closed defect (bug) (fixed)
get_categories does not return a valid wp_error
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.5 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Taxonomy | Keywords: | |
| Focuses: | Cc: |
Description
The get_categories() function does not return a valid wp_error object if an invalid taxonomy is passed in as a parameter.
For "invalid taxonomy" we can consider a taxonomy that does not exists or a taxonomy that is not yet registered.
As reported here: get_categories() is a wrapper for get_terms().
And get_terms return a wp_error object if fails.
BUT, inside the get_categories() function there is this casting:
$categories = (array) get_terms( $taxonomy, $args );
This type of casting convert the wp_error object into an array, losing the ability to recognize the error using is_wp_error() function.
I think this should be a bug.
Attachments (2)
Change History (6)
Note: See
TracTickets for help on using
tickets.
Yes, definitely a bug.
However, I don't think that returning a
WP_Errorobject is a wise solution. As far as I can see,get_categories()has always returned nothing but an array. Changing this now is likely to cause compatibility problems. And in any case, it's a convenience wrapper forget_terms()that does nothing much aside from_make_cat_compat(); and_make_cat_compat()only makes sense when you're fetchingcategoryterms, yet when you're fetchingcategoryterms you won't get aWP_Error. As such, if you need proper error reporting, and you're not fetchingcategoryterms, just useget_terms().See 36227.diff. Anyone see a problem with this?