Opened 9 years ago
Closed 9 years ago
#36227 closed defect (bug) (fixed)
get_categories does not return a valid wp_error
Reported by: | virgodesign | Owned by: | boonebgorges |
---|---|---|---|
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_Error
object 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 fetchingcategory
terms, yet when you're fetchingcategory
terms you won't get aWP_Error
. As such, if you need proper error reporting, and you're not fetchingcategory
terms, just useget_terms()
.See 36227.diff. Anyone see a problem with this?