Fix: Add null check to mention object before calling get_comment_date#343
Open
jan-vandenberg wants to merge 1 commit intoraamdev:masterfrom
Open
Fix: Add null check to mention object before calling get_comment_date#343jan-vandenberg wants to merge 1 commit intoraamdev:masterfrom
jan-vandenberg wants to merge 1 commit intoraamdev:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This prevents a "PHP Warning: Attempt to read property 'comment_date' on null" in the Apache error log when the
independent_publisher_mentionsfunction 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 618The stack trace points to the
independent_publisher_mentionsfunction ininc/independent-publisher-comments.php. The function callsget_comment_date( '', $mention )without verifying that the$mentionvariable holds a valid comment object (it can benull).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.