Skip to content

Conversation

@jeherve
Copy link
Member

@jeherve jeherve commented Jan 6, 2026

Fixes CMF-356

Proposed changes:

Since get_post can return null or an int, it's best to explicitely check for a WP_Post return.

This should avoid PHP warnings like this one:

Warning: Attempt to read property "post_content" on null in /public_html/wp-content/plugins/activitypub/includes/functions.php on line 114

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • This should be testable on a WordPress.com sandbox, since that's where the warnings are easily repeatable (see original issue).

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Fixes CMF-356

This should avoid PHP warnings like this one:

Warning: Attempt to read property "post_content" on null in /public_html/wp-content/plugins/activitypub/includes/functions.php on line 114
Copilot AI review requested due to automatic review settings January 6, 2026 08:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes PHP warnings that occur when get_post() returns null by adding explicit WP_Post instance checks in three methods that fetch remote actor data.

Key Changes:

  • Added instanceof \WP_Post validation after get_post() calls to prevent accessing properties on null values
  • Returns consistent WP_Error objects with appropriate error codes when post retrieval fails
  • Applied the fix to three methods: get_by_uri(), fetch_by_uri(), and fetch_by_acct()

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
includes/collection/class-remote-actors.php Added explicit WP_Post type checks in three methods to prevent PHP warnings when attempting to access post properties on null values
.github/changelog/fix-post-explicit-wp-post-return Added changelog entry documenting the patch-level fix

Review Summary: The changes are well-implemented and consistent across all three affected methods. The explicit type checking provides a robust defense against null pointer warnings and properly returns error objects that align with the existing error handling patterns in the codebase. No issues were identified during the review.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jeherve jeherve self-assigned this Jan 6, 2026
@jeherve jeherve requested a review from a team January 6, 2026 09:26
@jeherve
Copy link
Member Author

jeherve commented Jan 6, 2026

Tests are failing for a different root cause, that should get fixed in #2724

Copy link
Member

@pfefferle pfefferle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jeherve

@jeherve jeherve merged commit 5f57df4 into trunk Jan 7, 2026
10 checks passed
@jeherve jeherve deleted the fix/post-explicit-wp-post-return branch January 7, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants