Skip to content

Fix: Add null check to mention object before calling get_comment_date#343

Open
jan-vandenberg wants to merge 1 commit intoraamdev:masterfrom
jan-vandenberg:jan-vandenberg-patch-1
Open

Fix: Add null check to mention object before calling get_comment_date#343
jan-vandenberg wants to merge 1 commit intoraamdev:masterfrom
jan-vandenberg:jan-vandenberg-patch-1

Conversation

@jan-vandenberg
Copy link

This prevents a "PHP Warning: Attempt to read property 'comment_date' on null" in the Apache error log when the independent_publisher_mentions function attempts to process a mention (pingback/trackback) that is not a valid comment object.

Fixes PHP Warning: Attempt to read property "comment_date" on null

Description:

This PR resolves a persistent PHP Warning that appears in the error log, often triggered by bot activity or malformed requests trying to post comments/mentions:

PHP Warning: Attempt to read property "comment_date" on null in /wp-includes/comment-template.php on line 618

The stack trace points to the independent_publisher_mentions function in inc/independent-publisher-comments.php. The function calls get_comment_date( '', $mention ) without verifying that the $mention variable holds a valid comment object (it can be null).

Changes:

A simple if ( $mention ) check has been added around the mention link generation to ensure the object is valid before attempting to read its properties. This prevents the warning while maintaining existing functionality.

This prevents a "PHP Warning: Attempt to read property 'comment_date' on null" in the Apache error log when the `independent_publisher_mentions` function attempts to process a mention (pingback/trackback) that is not a valid comment object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant