[wp-trac] [WordPress Trac] #54379: `get_comment_ID()` can cause a notice within the `comment_text` filter

WordPress Trac noreply at wordpress.org
Thu Mar 3 20:32:36 UTC 2022

#54379: `get_comment_ID()` can cause a notice within the `comment_text` filter
 Reporter:  dd32          |       Owner:  davidbaumwald
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  6.0
Component:  Comments      |     Version:
 Severity:  normal        |  Resolution:  fixed
 Keywords:  has-patch     |     Focuses:
Changes (by davidbaumwald):

 * status:  reviewing => closed
 * resolution:   => fixed


 In [changeset:"52818" 52818]:
 #!CommitTicketReference repository="" revision="52818"
 Comments: Guard against potential PHP notices in `get_comment_author` and

 In both `get_comment_author` and `get_comment_ID`, it's possible that
 these functions are called without a comment context.  Specifically,
 `get_comment_author` can be called without passing the `$comment_ID`
 parameter, and `get_comment_ID` relies on the `comment` global if there's
 no `$comment` parameter supplied.  This leads to a PHP notice of "Trying
 to get property of a non-object."

 This change adds a check to both functions to ensure the
 `$comment->comment_ID` property is not empty before actually using its

 Follow-up to [52223].

 Props dd32.
 Fixes #54379.

Ticket URL: <https://core.trac.wordpress.org/ticket/54379#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list