[wp-trac] [WordPress Trac] #29660: Functions in wp_includes/query.php assume non-null return value from get_queried_object

WordPress Trac noreply at wordpress.org
Sat Jan 30 07:54:54 UTC 2016


#29660: Functions in wp_includes/query.php assume non-null return value from
get_queried_object
--------------------------+------------------
 Reporter:  yellyc        |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.5
Component:  Query         |     Version:  4.0
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------

Comment (by Howdy_McGee):

 I'm possibly repeating what is already known but since
 `$wp_query->get_queried_object()` sets the `$query_object` to `null`
 there's a possibly in current and future edge cases that it will return a
 non-object.

 For example - I hook into `pre_get_posts` and conditionally pass a non-
 existing term slug to `$wp_query->is_category( 'term-slug' )`. It goes and
 looks for the term using `get_term()` and `get_term_by()` which both
 return false and then the `$wp_query->is_category()` function attempts to
 get properties from a null object.

 This is not the case with `$wp_query->is_tax( 'taxonomy', 'term-slug' )`
 because of this little conditional in the function:


 {{{
 if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) &&
 in_array( $queried_object->taxonomy, $tax_array ) ) )
 }}}


 Now it seems like we either need to _always_ return an object from
 `$wp_query->get_query_object()` whose properties vary depending or start
 adding checks into the `is_*` functions for null values. Which one is more
 favorable because I could start patching the latter.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29660#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list