PluginProbe
ActivityPub / 3.2.4
ActivityPub v3.2.4
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
← All changes | includes/handler/class-create.php +42 -12 2.1.03.2.4 View file →
@@ -20,8 +20,15 @@
20 20 array( self::class, 'handle_create' ),
21 21 10,
22 22 3
23 23 );
24 +
25 + \add_filter(
26 + 'activitypub_validate_object',
27 + array( self::class, 'validate_object' ),
28 + 10,
29 + 3
30 + );
24 31 }
25 32
26 33 /**
27 34 * Handles "Create" requests
@@ -32,19 +39,8 @@
32 39 *
33 40 * @return void
34 41 */
35 42 public static function handle_create( $array, $user_id, $object = null ) {
36 - if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
37 - return;
38 - }
39 -
40 - if (
41 - ! isset( $array['object'] ) ||
42 - ! isset( $array['object']['id'] )
43 - ) {
44 - return;
45 - }
46 -
47 43 // check if Activity is public or not
48 44 if ( ! is_activity_public( $array ) ) {
49 45 // @todo maybe send email
50 46 return;
@@ -60,11 +56,45 @@
60 56
61 57 $state = Interactions::add_comment( $array );
62 58 $reaction = null;
63 59
64 - if ( $state && ! \is_wp_error( $reaction ) ) {
60 + if ( $state && ! \is_wp_error( $state ) ) {
65 61 $reaction = \get_comment( $state );
66 62 }
67 63
68 64 \do_action( 'activitypub_handled_create', $array, $user_id, $state, $reaction );
65 + }
66 +
67 + /**
68 + * Validate the object
69 + *
70 + * @param bool $valid The validation state
71 + * @param string $param The object parameter
72 + * @param \WP_REST_Request $request The request object
73 + * @param array $array The activity-object
74 + *
75 + * @return bool The validation state: true if valid, false if not
76 + */
77 + public static function validate_object( $valid, $param, $request ) {
78 + $json_params = $request->get_json_params();
79 +
80 + if (
81 + 'Create' !== $json_params['type'] ||
82 + is_wp_error( $request )
83 + ) {
84 + return $valid;
85 + }
86 +
87 + $object = $json_params['object'];
88 + $required = array(
89 + 'id',
90 + 'inReplyTo',
91 + 'content',
92 + );
93 +
94 + if ( array_intersect( $required, array_keys( $object ) ) !== $required ) {
95 + return false;
96 + }
97 +
98 + return $valid;
69 99 }
70 100 }