[wp-trac] [WordPress Trac] #36227: get_categories does not return a valid wp_error
WordPress Trac
noreply at wordpress.org
Sun Mar 13 15:05:24 UTC 2016
#36227: get_categories does not return a valid wp_error
--------------------------+-----------------------------
Reporter: virgodesign | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.4.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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
[https://developer.wordpress.org/reference/functions/get_categories/
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36227>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list