PluginProbe
ActivityPub / 2.5.0
ActivityPub v2.5.0
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 / class-announce.php

class-announce.php in ActivityPub 2.5.0, at includes/handler/class-announce.php

70 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Handler;
3
4 use Activitypub\Http;
5
6 use function Activitypub\is_activity_public;
7
8 /**
9 * Handle Create requests
10 */
11 class Announce {
12 /**
13 * Initialize the class, registering WordPress hooks
14 */
15 public static function init() {
16 \add_action(
17 'activitypub_inbox_announce',
18 array( self::class, 'handle_announce' ),
19 10,
20 3
21 );
22 }
23
24 /**
25 * Handles "Announce" requests
26 *
27 * @param array $array The activity-object
28 * @param int $user_id The id of the local blog-user
29 * @param Activitypub\Activity $activity The activity object
30 *
31 * @return void
32 */
33 public static function handle_announce( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
34 if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
35 return;
36 }
37
38 if ( ! isset( $array['object'] ) ) {
39 return;
40 }
41
42 // check if Activity is public or not
43 if ( ! is_activity_public( $array ) ) {
44 // @todo maybe send email
45 return;
46 }
47
48 // @todo save the `Announce`-Activity itself
49
50 if ( is_string( $array['object'] ) ) {
51 $object = Http::get_remote_object( $array['object'] );
52 } else {
53 $object = $array['object'];
54 }
55
56 if ( ! $object || is_wp_error( $object ) ) {
57 return;
58 }
59
60 if ( ! isset( $object['type'] ) ) {
61 return;
62 }
63
64 $type = \strtolower( $object['type'] );
65
66 \do_action( 'activitypub_inbox', $object, $user_id, $type, $activity );
67 \do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity );
68 }
69 }
70