# activitypub/2.5.0/includes/handler/class-undo.php

ActivityPub, version 2.5.0. 51 lines.

- Page: https://pluginprobe.com/plugins/activitypub/2.5.0/code/includes/handler/class-undo.php
- Raw: https://pluginprobe.com/plugins/activitypub/2.5.0/raw/includes/handler/class-undo.php
- Modified: 2024-04-29T08:01:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/activitypub/2.5.0/code/includes/handler/class-undo.php#L10-L20`.

```php
<?php
namespace Activitypub\Handler;

use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;

use function Activitypub\object_to_uri;

/**
 * Handle Undo requests
 */
class Undo {
	/**
	 * Initialize the class, registering WordPress hooks
	 */
	public static function init() {
		\add_action(
			'activitypub_inbox_undo',
			array( self::class, 'handle_undo' )
		);
	}

	/**
	 * Handle "Unfollow" requests
	 *
	 * @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 ) {
		if (
			isset( $activity['object']['type'] ) &&
			'Follow' === $activity['object']['type'] &&
			isset( $activity['object']['object'] )
		) {
			$user_id = object_to_uri( $activity['object']['object'] );
			$user = Users::get_by_resource( $user_id );

			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();
			$actor   = object_to_uri( $activity['actor'] );

			Followers::remove_follower( $user_id, $actor );
		}
	}
}

```
