[wp-trac] [WordPress Trac] #57615: Various comment functions reporting error when `get_comment()` returns `null`

WordPress Trac noreply at wordpress.org
Thu Feb 2 21:14:08 UTC 2023


#57615: Various comment functions reporting error when `get_comment()` returns
`null`
--------------------------+-----------------------------
 Reporter:  thomasplevy   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  trunk
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 While working on #53290 I noticed that if the function
 `get_comment_author_link()` is called with no value passed into it or if
 an invalid comment ID is passed into the function an error is thrown on
 the return filter:

 {{{
 Trying to get property 'comment_ID' of non-object
 wp-includes/comment-template.php:242
 }}}

 While gathering information to report this I also noticed several other
 functions in the same file, `wp-includes/comment-template.php` will suffer
 from the same or a similar issue:

 + `comment_author()`
 + `get_comment_author_email()`
 + `comment_author_email()`
 + `get_comment_author_IP()`
 + `comment_author_url()`
 + `get_comment_excerpt()`
 + `comment_excerpt()`
 + `get_comment_type()`


 Some of the functions in this file, `get_comment_author()` for example,
 store the comment ID as a variable and pass that into the return filter:

 `$comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID :
 $comment_ID;`

 I'm currently working on writing tests since most of the functions I'm
 mentioned don't have existing test coverage.

 I'm also uploading a patch with my proposed solution. If this seems like
 the right direction to go I'll add changes to the remaining functions and
 update the patch (and tests).

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


More information about the wp-trac mailing list