Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#57615 new defect (bug)

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

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

Description

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

Attachments (1)

57615.patch​ (3.1 KB ) - added by thomasplevy 4 years ago.

Download all attachments as: .zip

Change History (5)

@thomasplevy
4 years ago

#1 @SergeyBiryukov
4 years 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.


4 years ago
#2

  • Keywords has-patch has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/57615

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

​thomasplevy commented on ​PR #3980:


4 years ago
#3

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
4 years ago

  • Version trunk

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.