[wp-trac] [WordPress Trac] #36992: In get_terms(), getting a fatal error iterating on $terms inside get_terms filter.

WordPress Trac noreply at wordpress.org
Wed Jun 1 23:02:33 UTC 2016


#36992: In get_terms(), getting a fatal error iterating on $terms inside get_terms
filter.
---------------------------+-----------------------------
 Reporter:  JustinSainton  |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Taxonomy       |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Our plugin (WP eCommerce) has a filter on get_terms for some custom
 sorting.

 In WP 4.5.2,
 [https://gist.github.com/JustinSainton/002920bb0e9e7426bbdee6ad07ef232c
 #file-gistfile1-txt-L6 this code] works fine.  In trunk, it is broken.

 After [https://wordpress.slack.com/archives/core/p1464821518008072
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36992>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list