[wp-trac] [WordPress Trac] #63263: check if exists before accessing object properties of $post->comment_count

WordPress Trac noreply at wordpress.org
Fri Apr 11 09:22:36 UTC 2025


#63263: check if exists before accessing object properties of $post->comment_count
--------------------------+-----------------------------
 Reporter:  Presskopp     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I got a

 **Warning: Attempt to read property "comment_count" on null in [...]\wp-
 includes\general-template.php on line 3352**

 let's check if the object exists and the property is not empty.

 Original line:

 {{{if ( $show_post_comments_feed && ( comments_open() || pings_open() ||
 $post->comment_count > 0 ) ) {}}}

 possible patch, something like:

 {{{
 if ( $show_post_comments_feed
      && isset( $post )
      && $post instanceof WP_Post
      && ( comments_open() || pings_open() || $post->comment_count > 0 )
 ) {
 }}}

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


More information about the wp-trac mailing list