| 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 |
|