Opened 8 years ago
Closed 8 years ago
#36992 closed defect (bug) (fixed)
In get_terms(), getting a fatal error iterating on $terms inside get_terms filter.
Reported by: | JustinSainton | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
Our plugin (WP eCommerce) has a filter on get_terms for some custom sorting.
In WP 4.5.2, this code works fine. In trunk, it is broken.
After chatting a bit with @boone, our best guess is that the move to WP_Term_Query moved the filtering of get_terms() so that counts are now filtered, and before, they likely were not.
To be clear - the fault is in our code (we should have assumed possible return types of int, WP_Error, or an array), but there is a clear change in core.
For us, the intermediate solution is to simply add an is_array() check and return early. For core, it may be worth ensuring that the values are only filtered in the same places that they were in previous versions of WordPress.
Change History (9)
#4
@
8 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 37623:
#5
follow-up:
↓ 6
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
FWIW, this is still somewhat broken. I've not had a chance to chase down why, but if you use array type hinting in your callback on the get_terms
filter, you get the following error.
Catchable fatal error: Argument 1 passed to genesis_get_terms_filter() must be of the type array, string given
Obviously, this is in the Genesis theme.
Anybody know what's going on here? Why is a argument not of type array
ever being passed to the get_terms
filter?
#6
in reply to:
↑ 5
@
8 years ago
- Keywords reporter-feedback added
Replying to nathanrice:
FWIW, this is still somewhat broken. I've not had a chance to chase down why, but if you use array type hinting in your callback on the
get_terms
filter, you get the following error.
Catchable fatal error: Argument 1 passed to genesis_get_terms_filter() must be of the type array, string given
Obviously, this is in the Genesis theme.
Anybody know what's going on here? Why is a argument not of type
array
ever being passed to theget_terms
filter?
I just looked through again. At a glance, I don't see anywhere where something other than an array might be passed through the filter. It would be helpful if you could generate a full stack trace, including (a) the args being passed to get_terms()
and WP_Term_Query
, and (b) the non-array value that's being erroneously passed to the filter (is it a WP_Error
? a boolean? or something else?)
#7
@
8 years ago
This was sent by one of our testers. I can also send a copy of Genesis to you if you want to see any of this for yourself.
[03-Jun-2016 12:05:56 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to genesis_get_terms_filter() must be of the type array, string given, called in /Users/nickcernis/www/trunk/wp-includes/plugin.php on line 235 and defined in /Users/nickcernis/www/trunk/wp-content/themes/genesis/lib/admin/term-meta.php:268 Stack trace: #0 /Users/nickcernis/www/trunk/wp-includes/plugin.php(235): genesis_get_terms_filter('2', Array) #1 /Users/nickcernis/www/trunk/wp-includes/taxonomy.php(1227): apply_filters('get_terms', '2', Array, Array, Object(WP_Term_Query)) #2 /Users/nickcernis/www/trunk/wp-includes/taxonomy.php(1694): get_terms(Array, Array) #3 /Users/nickcernis/www/trunk/wp-admin/includes/class-wp-terms-list-table.php(127): wp_count_terms('category', Array) #4 /Users/nickcernis/www/trunk/wp-admin/edit-tags.php(212): WP_Terms_List_Table->prepare_items() #5 {main} thrown in /Users/nickcernis/www/trunk/wp-content/themes/genesis/lib/admin/term-meta.php on line 268
Update: Confirmed @boonebgorges' suspicion: https://github.com/WordPress/WordPress/blob/4.5.2/wp-includes/taxonomy.php#L1640-L1642
Also, existing code has an unused remnant variable.