PluginProbe
ActivityPub / trunk
ActivityPub vtrunk
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / handler / outbox / class-block.php

class-block.php in ActivityPub trunk, at includes/handler/outbox/class-block.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Outbox Block handler file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Handler\Outbox;
9
10 use Activitypub\Moderation;
11
12 use function Activitypub\add_to_outbox;
13 use function Activitypub\object_to_uri;
14
15 /**
16 * Handle outgoing Block activities.
17 */
18 class Block {
19 /**
20 * Initialize the class, registering WordPress hooks.
21 */
22 public static function init() {
23 \add_filter( 'activitypub_outbox_block', array( self::class, 'handle_block' ), 10, 2 );
24 }
25
26 /**
27 * Handle outgoing "Block" activities from local actors.
28 *
29 * Blocks a remote actor using the Moderation system, then adds
30 * the activity to the outbox for federation.
31 *
32 * @since 8.1.0
33 *
34 * @param array $data The activity data array.
35 * @param int $user_id The user ID.
36 *
37 * @return array|int|\WP_Error The original data if unhandled, outbox post ID on success, or WP_Error on failure.
38 */
39 public static function handle_block( $data, $user_id = null ) {
40 $actor_uri = object_to_uri( $data['object'] ?? '' );
41
42 if ( empty( $actor_uri ) ) {
43 return $data;
44 }
45
46 $result = Moderation::add_user_block( $user_id, Moderation::TYPE_ACTOR, $actor_uri );
47
48 if ( ! $result ) {
49 return new \WP_Error(
50 'activitypub_block_failed',
51 \__( 'Failed to block the actor.', 'activitypub' ),
52 array( 'status' => 500 )
53 );
54 }
55
56 // Block activities should only be sent to the blocked actor.
57 $data['to'] = array( $actor_uri );
58 unset( $data['cc'] );
59
60 return add_to_outbox( $data, 'Block', $user_id, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
61 }
62 }
63