Skip to content

Commit 6e5c0d7

Browse files
authored
Fix fatal error in Stream connector on new follower (#3372)
1 parent 360ea77 commit 6e5c0d7

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fix a fatal error when receiving a new follower while the Stream plugin is active.

integration/stream/class-connector.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ public function action_links( $links, $record ) {
111111
/**
112112
* Callback for activitypub_handled_follow.
113113
*
114-
* @param array $activity The ActivityPub activity data.
115-
* @param int|null $user_id The local user ID, or null if not applicable.
116-
* @param mixed $state Status or WP_Error object indicating the result of the follow handling.
117-
* @param \WP_Post|null $context The WP_Post object representing the remote actor/follower.
114+
* @param array $activity The ActivityPub activity data.
115+
* @param int|int[] $user_ids The local user ID(s) of the followed actor(s).
116+
* @param bool $success Whether the follow was handled successfully.
117+
* @param \WP_Post|\WP_Error $context The remote actor/follower, or WP_Error on failure.
118118
*/
119-
public function callback_activitypub_handled_follow( $activity, $user_id, $state, $context ) {
119+
public function callback_activitypub_handled_follow( $activity, $user_ids, $success, $context ) {
120+
// The hook passes an array of user IDs; Stream's log() builds a WP_User from this, so coerce to a single integer.
121+
$user_id = (int) ( \is_array( $user_ids ) ? \reset( $user_ids ) : $user_ids );
120122
$actor_url = \is_object( $context ) && ! \is_wp_error( $context ) ? $context->guid : $activity['actor'];
121123

122124
$this->log(

tests/phpunit/tests/integration/class-test-stream-connector.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,16 @@ function ( $message, $meta, $object_id, $context_type, $action, $user_id ) use (
284284
}
285285
);
286286

287-
$stream_connector->callback_activitypub_handled_follow( $activity, self::$user_id, true, $context );
287+
// The "activitypub_handled_follow" hook fires with an array of user IDs (int[]).
288+
$stream_connector->callback_activitypub_handled_follow( $activity, array( self::$user_id ), true, $context );
288289

289290
$this->assertNotNull( $logged_data, 'Should have logged the follow event' );
290291
$this->assertStringContainsString( 'New Follower: https://example.com/actor', $logged_data['message'] );
291292
$this->assertEquals( 'notification', $logged_data['context_type'] );
292293
$this->assertEquals( 'follow', $logged_data['action'] );
293-
$this->assertEquals( self::$user_id, $logged_data['user_id'] );
294+
// Stream's log() builds a WP_User from this value, so it must be a single integer, not the array.
295+
$this->assertIsInt( $logged_data['user_id'], 'Stream log() must receive a single integer user ID, not an array.' );
296+
$this->assertSame( self::$user_id, $logged_data['user_id'] );
294297
$this->assertArrayHasKey( 'activity', $logged_data['meta'] );
295298
$this->assertArrayHasKey( 'remote_actor', $logged_data['meta'] );
296299
}
@@ -327,7 +330,8 @@ function ( $message, $meta ) use ( &$logged_data ) {
327330
}
328331
);
329332

330-
$stream_connector->callback_activitypub_handled_follow( $activity, self::$user_id, false, $context );
333+
// The "activitypub_handled_follow" hook fires with an array of user IDs (int[]).
334+
$stream_connector->callback_activitypub_handled_follow( $activity, array( self::$user_id ), false, $context );
331335

332336
$this->assertStringContainsString( 'New Follower: https://example.com/actor', $logged_data['message'] );
333337
}

0 commit comments

Comments
 (0)