Skip to content

Fix PHP deprecation and missing federation when replying to remote Fediverse posts#291

Merged
akirk merged 2 commits intomainfrom
fix-remote-reply-comment-post-id
Apr 7, 2026
Merged

Fix PHP deprecation and missing federation when replying to remote Fediverse posts#291
akirk merged 2 commits intomainfrom
fix-remote-reply-comment-post-id

Conversation

@akirk
Copy link
Copy Markdown
Owner

@akirk akirk commented Apr 4, 2026

Fixes the issue reported at https://wordpress.org/support/topic/latest-1-5-1-still-provides-errors-when-remotely-replying-to-fediverse-posts/

Problem

When replying to a remote Fediverse post (one resolved via the search endpoint), the mastodon_api_in_reply_to_id filter converts the numeric ID back to the original remote URL (e.g. https://social.thelab.uno/@ggrey/116312656735329169).

api_submit_comment then received this URL string as $in_reply_to_id, couldn't find a matching comment, and set comment_post_ID to the URL string. Calling wp_insert_comment() with a URL as comment_post_ID triggered:

PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in wp-includes/comment.php on line 1422

The reply also never federated to the Fediverse because no proper post was created.

Replying to local posts and to followed remote users worked fine; only unfollowed remote posts were affected.

Fix

api_submit_comment: Added a guard — if comment_post_ID doesn't resolve to a real local post, return early and fall through to api_submit_post. This prevents the invalid wp_insert_comment() call.

prepare_post_data: When $in_reply_to_id is a URL (non-numeric), store it as activitypub_in_reply_to post meta — the same pattern the Friends plugin uses for its reply UI — rather than embedding it as a Gutenberg block in the post content (which would also render as a visible embed on the frontend).

activitypub_in_reply_to_object_array: New filter callback on activitypub_activity_object_array that injects inReplyTo into the ActivityPub object from the activitypub_in_reply_to meta at federation time.

Test

Added test_submit_status_reply_to_remote_post verifying that:

  • No comment is created (avoiding the PHP deprecation)
  • A new post is created instead
  • The activitypub_in_reply_to meta is set to the remote URL
  • Post content does not contain an activitypub/reply block

akirk added 2 commits April 4, 2026 22:00
…diverse posts

When replying to a remote post (resolved via search), the in_reply_to_id
filter maps the numeric ID back to the original URL. api_submit_comment
was blindly setting comment_post_ID to that URL string and calling
wp_insert_comment() with invalid data, triggering:
  preg_match(): Passing null to parameter #2 ($subject)
The reply was also never federated since no proper post was created.

Fix api_submit_comment to skip comment creation when comment_post_ID
doesn't correspond to a real local post, falling through to api_submit_post.

Fix prepare_post_data to handle a URL-based in_reply_to_id by prepending
an activitypub/reply block to the post content (rather than setting an
invalid post_parent), so the ActivityPub plugin can federate the reply
to the correct remote URL.
…or remote replies

Instead of embedding an activitypub/reply Gutenberg block into post content
(which also renders as a visible embed on the frontend), store the remote
URL cleanly as activitypub_in_reply_to post meta — the same approach the
Friends plugin uses for its reply UI.

Add an activitypub_activity_object_array filter to inject inReplyTo into
the ActivityPub object from the meta at federation time.
@akirk akirk merged commit 91b7d23 into main Apr 7, 2026
17 checks passed
@akirk akirk deleted the fix-remote-reply-comment-post-id branch April 7, 2026 08:10
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