PluginProbe
ActivityPub / 2.6.0
ActivityPub v2.6.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/handler/class-undo.php +23 -4 1.3.02.6.0 View file →
@@ -1,9 +1,12 @@
1 1 <?php
2 2 namespace Activitypub\Handler;
3 3
4 +use Activitypub\Collection\Users;
4 5 use Activitypub\Collection\Followers;
5 6
7 +use function Activitypub\object_to_uri;
8 +
6 9 /**
7 10 * Handle Undo requests
8 11 */
9 12 class Undo {
@@ -10,9 +13,12 @@
10 13 /**
11 14 * Initialize the class, registering WordPress hooks
12 15 */
13 16 public static function init() {
14 - \add_action( 'activitypub_inbox_undo', array( self::class, 'handle_undo' ), 10, 2 );
17 + \add_action(
18 + 'activitypub_inbox_undo',
19 + array( self::class, 'handle_undo' )
20 + );
15 21 }
16 22
17 23 /**
18 24 * Handle "Unfollow" requests
@@ -19,13 +25,26 @@
19 25 *
20 26 * @param array $activity The JSON "Undo" Activity
21 27 * @param int $user_id The ID of the ID of the WordPress User
22 28 */
23 - public static function handle_undo( $activity, $user_id ) {
29 + public static function handle_undo( $activity ) {
24 30 if (
25 31 isset( $activity['object']['type'] ) &&
26 - 'Follow' === $activity['object']['type']
32 + 'Follow' === $activity['object']['type'] &&
33 + isset( $activity['object']['object'] )
27 34 ) {
28 - Followers::remove_follower( $user_id, $activity['actor'] );
35 + $user_id = object_to_uri( $activity['object']['object'] );
36 + $user = Users::get_by_resource( $user_id );
37 +
38 + if ( ! $user || is_wp_error( $user ) ) {
39 + // If we can not find a user,
40 + // we can not initiate a follow process
41 + return;
42 + }
43 +
44 + $user_id = $user->get__id();
45 + $actor = object_to_uri( $activity['actor'] );
46 +
47 + Followers::remove_follower( $user_id, $actor );
29 48 }
30 49 }
31 50 }