Fix fatal error in Stream connector on new follower#3372
Conversation
The activitypub_handled_follow hook passes the user IDs as an array (int[]) since 7.5.0, but Stream's callback_activitypub_handled_follow forwarded that array straight into WP_Stream\Connector::log()'s $user_id parameter. Stream then built a WP_User from the array, which triggered an uncaught TypeError (trim() on an array) and fataled every inbound Follow on sites with the Stream plugin active. Normalize the user IDs to a single integer in the callback, mirroring the pattern already used by the Follow handler, Mailer, and Event Stream consumers. Update the existing tests to pass the array the hook actually emits and assert the logged user ID is a scalar int.
|
This likely resolves the user report at https://wordpress.org/support/topic/follow-activity-reverts-from-unfollow-to-confirm-request/. Why the symptom matches: the Caveat: this only explains the report if the affected site has the Stream plugin active — the fatal originates in the Stream connector. Sites without Stream would need a different explanation. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a fatal error in the Stream integration when handling inbound Follow activities by aligning the Stream connector with the activitypub_handled_follow hook’s current signature (user IDs passed as an int[] since 7.5.0).
Changes:
- Update Stream connector follow callback to normalize the hook’s user IDs argument before logging.
- Adjust Stream connector integration tests to pass the array form the hook actually emits.
- Add a patch-level changelogger entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
integration/stream/class-connector.php |
Normalizes user_ids for Stream logging to avoid passing an array into Stream’s user resolution. |
tests/phpunit/tests/integration/class-test-stream-connector.php |
Updates tests to call the callback with int[] and asserts Stream receives a scalar user ID. |
.github/changelog/fix-stream-follower-fatal |
Adds a patch/fixed changelog entry for the Stream follower fatal error. |
- Fix the callback docblock: the third arg is the boolean success flag and $context is WP_Post|WP_Error (not WP_Post|null). - Cast the resolved user ID to int so Stream's log() (which builds a WP_User) always receives a scalar, even for an empty user IDs array.
|
Thanks @copilot — both addressed in 260fa27:
CI is green across PHP 7.4 / 8.3 / 8.5. |
Proposed changes:
Fixes a fatal error on every inbound Follow for any site running the Stream plugin.
Since 7.5.0, the
activitypub_handled_followhook passes its user IDs as an array (int[]). The Stream integration'scallback_activitypub_handled_follow()still treated that argument as a scalar and forwarded the array straight intoWP_Stream\Connector::log()'s$user_idparameter. Stream then built aWP_Userfrom the array:The fix normalizes the user IDs to a single integer in the callback (
\is_array( $user_ids ) ? \reset( $user_ids ) : $user_ids), mirroring the pattern already used by every other consumer of this hook (Follow::queue_accept,Mailer::new_follower,Event_Stream::signal_inbox). I audited all consumers of the(array) $user_idshooks — the Stream follow callback was the only one mishandling the array.Other information:
Testing instructions:
do_action( 'activitypub_handled_follow', $activity, array( 1 ), true, $remote_actor )).TypeErrorinclass-wp-user.php. After: the follow is logged to Stream as "New Follower" with no error.npm run env-test -- --filter='Follow|Stream'→ all green.Changelog entry
A changelog entry is already included in this PR (
.github/changelog/fix-stream-follower-fatal, patch / fixed), so the automatic entry box is left unchecked.