laipower/wp-content/upgrade-temp-backup/plugins/activitypub/includes/handler/class-undo.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2024-02-08 12:31:51 +00:00
<?php
namespace Activitypub\Handler;
2024-03-28 09:40:10 +00:00
use Activitypub\Collection\Users;
2024-02-08 12:31:51 +00:00
use Activitypub\Collection\Followers;
/**
* Handle Undo requests
*/
class Undo {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
2024-03-28 09:40:10 +00:00
\add_action(
'activitypub_inbox_undo',
array( self::class, 'handle_undo' )
);
2024-02-08 12:31:51 +00:00
}
/**
* Handle "Unfollow" requests
*
* @param array $activity The JSON "Undo" Activity
* @param int $user_id The ID of the ID of the WordPress User
*/
2024-03-28 09:40:10 +00:00
public static function handle_undo( $activity ) {
2024-02-08 12:31:51 +00:00
if (
isset( $activity['object']['type'] ) &&
2024-03-28 09:40:10 +00:00
'Follow' === $activity['object']['type'] &&
isset( $activity['object']['object'] ) &&
filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
2024-02-08 12:31:51 +00:00
) {
2024-03-28 09:40:10 +00:00
$user = Users::get_by_resource( $activity['object']['object'] );
if ( ! $user || is_wp_error( $user ) ) {
// If we can not find a user,
// we can not initiate a follow process
return;
}
$user_id = $user->get__id();
2024-02-08 12:31:51 +00:00
Followers::remove_follower( $user_id, $activity['actor'] );
}
}
}