PluginProbe
ActivityPub / 1.3.0
ActivityPub v1.3.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-create.php

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

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