PluginProbe
ActivityPub / 2.4.0
ActivityPub v2.4.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
activitypub / includes / handler / class-undo.php

class-undo.php in ActivityPub 2.4.0, at includes/handler/class-undo.php

51 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Handler;
3
4 use Activitypub\Collection\Users;
5 use Activitypub\Collection\Followers;
6
7 use function Activitypub\object_to_uri;
8
9 /**
10 * Handle Undo requests
11 */
12 class Undo {
13 /**
14 * Initialize the class, registering WordPress hooks
15 */
16 public static function init() {
17 \add_action(
18 'activitypub_inbox_undo',
19 array( self::class, 'handle_undo' )
20 );
21 }
22
23 /**
24 * Handle "Unfollow" requests
25 *
26 * @param array $activity The JSON "Undo" Activity
27 * @param int $user_id The ID of the ID of the WordPress User
28 */
29 public static function handle_undo( $activity ) {
30 if (
31 isset( $activity['object']['type'] ) &&
32 'Follow' === $activity['object']['type'] &&
33 isset( $activity['object']['object'] )
34 ) {
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 );
48 }
49 }
50 }
51