updated plugin ActivityPub version 2.0.1

This commit is contained in:
2024-02-08 12:31:25 +00:00
committed by Gitium
parent 6e1c54f7ba
commit 50bf15833c
58 changed files with 1772 additions and 543 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace Activitypub\Handler;
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
/**
@ -11,7 +12,10 @@ class Undo {
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_action( 'activitypub_inbox_undo', array( self::class, 'handle_undo' ), 10, 2 );
\add_action(
'activitypub_inbox_undo',
array( self::class, 'handle_undo' )
);
}
/**
@ -20,11 +24,23 @@ class Undo {
* @param array $activity The JSON "Undo" Activity
* @param int $user_id The ID of the ID of the WordPress User
*/
public static function handle_undo( $activity, $user_id ) {
public static function handle_undo( $activity ) {
if (
isset( $activity['object']['type'] ) &&
'Follow' === $activity['object']['type']
'Follow' === $activity['object']['type'] &&
isset( $activity['object']['object'] ) &&
filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
) {
$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();
Followers::remove_follower( $user_id, $activity['actor'] );
}
}