| 1 |
<?php |
| 2 |
/** |
| 3 |
* Outbox Follow handler file. |
| 4 |
* |
| 5 |
* @package Activitypub |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Activitypub\Handler\Outbox; |
| 9 |
|
| 10 |
use function Activitypub\follow; |
| 11 |
use function Activitypub\object_to_uri; |
| 12 |
|
| 13 |
/** |
| 14 |
* Handle outgoing Follow activities. |
| 15 |
*/ |
| 16 |
class Follow { |
| 17 |
/** |
| 18 |
* Initialize the class, registering WordPress hooks. |
| 19 |
*/ |
| 20 |
public static function init() { |
| 21 |
\add_filter( 'activitypub_outbox_follow', array( self::class, 'handle_follow' ), 10, 2 ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Handle outgoing "Follow" activities from local actors. |
| 26 |
* |
| 27 |
* Delegates to the follow() function which handles pending state, |
| 28 |
* proper activity addressing, and adding to the outbox. |
| 29 |
* |
| 30 |
* @param array $data The activity data array. |
| 31 |
* @param int $user_id The user ID. |
| 32 |
* |
| 33 |
* @return int|\WP_Error The outbox post ID on success, or WP_Error on failure. |
| 34 |
*/ |
| 35 |
public static function handle_follow( $data, $user_id = null ) { |
| 36 |
$object = object_to_uri( $data['object'] ?? '' ); |
| 37 |
|
| 38 |
if ( empty( $object ) ) { |
| 39 |
return $data; |
| 40 |
} |
| 41 |
|
| 42 |
return follow( $object, $user_id ); |
| 43 |
} |
| 44 |
} |
| 45 |
|