PluginProbe
ActivityPub / 2.1.1
ActivityPub v2.1.1
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.1.1, at includes/handler/class-undo.php

48 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 /**
8 * Handle Undo requests
9 */
10 class Undo {
11 /**
12 * Initialize the class, registering WordPress hooks
13 */
14 public static function init() {
15 \add_action(
16 'activitypub_inbox_undo',
17 array( self::class, 'handle_undo' )
18 );
19 }
20
21 /**
22 * Handle "Unfollow" requests
23 *
24 * @param array $activity The JSON "Undo" Activity
25 * @param int $user_id The ID of the ID of the WordPress User
26 */
27 public static function handle_undo( $activity ) {
28 if (
29 isset( $activity['object']['type'] ) &&
30 'Follow' === $activity['object']['type'] &&
31 isset( $activity['object']['object'] ) &&
32 filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
33 ) {
34 $user = Users::get_by_resource( $activity['object']['object'] );
35
36 if ( ! $user || is_wp_error( $user ) ) {
37 // If we can not find a user,
38 // we can not initiate a follow process
39 return;
40 }
41
42 $user_id = $user->get__id();
43
44 Followers::remove_follower( $user_id, $activity['actor'] );
45 }
46 }
47 }
48