Make WordPress Core

Opened 15 months ago

Last modified 14 months ago

#57615 new defect (bug)

Various comment functions reporting error when `get_comment()` returns `null`

Reported by: thomasplevy's profile thomasplevy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:


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

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).

Attachments (1)

57615.patch (3.1 KB) - added by thomasplevy 15 months ago.

Download all attachments as: .zip

Change History (5)

15 months ago

#1 @SergeyBiryukov
15 months ago

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Just linking to some related tickets here: #40143, #54149.

This ticket was mentioned in PR #3980 on WordPress/wordpress-develop by thomasplevy.

15 months ago

  • Keywords has-patch has-unit-tests added

Trac ticket:

Updated the functions I mentioned in the trac ticket and wrote / updated unit tests for related code.

thomasplevy commented on PR #3980:

15 months ago

I swore that I read a while back the the null coalesce operator was now allowed by the WP coding standards now but in rereading I was incorrect, it said the null coalesce *will be allowed* when the PHP minimum is raised to 7.0. I'll update shortly.

#4 @hellofromTonya
14 months ago

  • Version trunk deleted

Removing trunk as the Version as the issue does not appear to be introduced in the 6.2.0 cycle.

Note: See TracTickets for help on using tickets.