PluginProbe
ActivityPub / 2.0.1
ActivityPub v2.0.1
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-create.php

class-create.php in ActivityPub 2.0.1, at includes/handler/class-create.php

67 lines 1.4 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 WP_Error;
5 use Activitypub\Collection\Interactions;
6
7 use function Activitypub\is_activity_public;
8 use function Activitypub\object_id_to_comment;
9
10 /**
11 * Handle Create requests
12 */
13 class Create {
14 /**
15 * Initialize the class, registering WordPress hooks
16 */
17 public static function init() {
18 \add_action(
19 'activitypub_inbox_create',
20 array( self::class, 'handle_create' ),
21 10,
22 3
23 );
24 }
25
26 /**
27 * Handles "Create" requests
28 *
29 * @param array $array The activity-object
30 * @param int $user_id The id of the local blog-user
31 * @param Activitypub\Activity $object The activity object
32 *
33 * @return void
34 */
35 public static function handle_create( $array, $user_id, $object = null ) {
36 if (
37 ! isset( $array['object'] ) ||
38 ! isset( $array['object']['id'] )
39 ) {
40 return;
41 }
42
43 // check if Activity is public or not
44 if ( ! is_activity_public( $array ) ) {
45 // @todo maybe send email
46 return;
47 }
48
49 $check_dupe = object_id_to_comment( $array['object']['id'] );
50
51 // if comment exists, call update action
52 if ( $check_dupe ) {
53 \do_action( 'activitypub_inbox_update', $array, $user_id, $object );
54 return;
55 }
56
57 $state = Interactions::add_comment( $array );
58 $reaction = null;
59
60 if ( $state && ! \is_wp_error( $reaction ) ) {
61 $reaction = \get_comment( $state );
62 }
63
64 \do_action( 'activitypub_handled_create', $array, $user_id, $state, $reaction );
65 }
66 }
67