[wp-trac] [WordPress Trac] #21394: query.php: get_queried_object() result cannot be assumed to be non-NULL

WordPress Trac noreply at wordpress.org
Fri Apr 1 17:46:05 UTC 2016


#21394: query.php: get_queried_object() result cannot be assumed to be non-NULL
------------------------------+-----------------------------
 Reporter:  lkraav            |       Owner:  wonderboymusic
     Type:  defect (bug)      |      Status:  closed
 Priority:  normal            |   Milestone:  3.7
Component:  Warnings/Notices  |     Version:  3.3.2
 Severity:  normal            |  Resolution:  fixed
 Keywords:  has-patch         |     Focuses:
------------------------------+-----------------------------

Comment (by danbrellis):

 I know this ticket is set to fixed, and I apologize if I'm not following
 protocol for bringing up a related issue, but I just had this problem and
 was able to trace it back to WP_Query::is_singular()

 In my case the plugin bbPress is making calls to is_singular() and when
 I'm viewing an RSS Feed, WP_Query::get_queried_object() returns NULL.
 However, WP_Query::is_singular() still checks if the result of
 get_queried_object() has the property `post_type`.

 The error I'm getting in my RSS is `<b>Notice</b>:  Trying to get property
 of non-object in <b>C:\Apache24\htdocs\bp-dev\wp-includes\query.php</b> on
 line <b>4654</b><br />`

 I would assume applying a similar fix to WP_Query::is_singular() would
 suffice?

 {{{#!php
 public function is_singular( $post_types = '' ) {
   if ( empty( $post_types ) || !$this->is_singular )
     return (bool) $this->is_singular;

   $post_obj = $this->get_queried_object();
   if (is_null($post_obj)) return false;
   return in_array( $post_obj->post_type, (array) $post_types );
 }
 }}}

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


More information about the wp-trac mailing list