PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.2
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-move.php +24 -19 9.2.07.8.2 View file →
@@ -25,8 +25,9 @@
25 25 * Initialize the class, registering WordPress hooks.
26 26 */
27 27 public static function init() {
28 28 \add_action( 'activitypub_inbox_move', array( self::class, 'handle_move' ), 10, 2 );
29 + \add_filter( 'activitypub_get_outbox_activity', array( self::class, 'outbox_activity' ) );
29 30 }
30 31
31 32 /**
32 33 * Handle Move requests.
@@ -61,10 +62,10 @@
61 62 global $wpdb;
62 63 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
63 64 $wpdb->update(
64 65 $wpdb->posts,
65 - array( 'guid' => \sanitize_url( $target_uri ) ),
66 - array( 'ID' => \sanitize_key( $origin_object->ID ) )
66 + array( 'guid' => sanitize_url( $target_uri ) ),
67 + array( 'ID' => sanitize_key( $origin_object->ID ) )
67 68 );
68 69
69 70 // Clear the cache.
70 71 \wp_cache_delete( $origin_object->ID, 'posts' );
@@ -69,11 +70,9 @@
69 70 // Clear the cache.
70 71 \wp_cache_delete( $origin_object->ID, 'posts' );
71 72
72 73 $success = true;
73 -
74 - // get_remote_object() already self-confirmed the target, so it is safe to cache.
75 - $result = Remote_Actors::upsert( $target_json );
74 + $result = Remote_Actors::upsert( $target_json );
76 75 }
77 76
78 77 // If both the target and origin are followed, merge them.
79 78 if ( ! \is_wp_error( $target_object ) && ! \is_wp_error( $origin_object ) ) {
@@ -102,8 +101,24 @@
102 101 \do_action( 'activitypub_handled_move', $activity, (array) $user_ids, $success, $result );
103 102 }
104 103
105 104 /**
105 + * Convert the object and origin to the correct format.
106 + *
107 + * @param \Activitypub\Activity\Activity $activity The Activity object.
108 + * @return \Activitypub\Activity\Activity The filtered Activity object.
109 + */
110 + public static function outbox_activity( $activity ) {
111 + if ( 'Move' === $activity->get_type() ) {
112 + $activity->set_object( object_to_uri( $activity->get_object() ) );
113 + $activity->set_origin( $activity->get_actor() );
114 + $activity->set_target( $activity->get_object() );
115 + }
116 +
117 + return $activity;
118 + }
119 +
120 + /**
106 121 * Extract the target from the activity.
107 122 *
108 123 * The ActivityStreams spec define the `target` attribute as the
109 124 * destination of the activity, but Mastodon uses the `object`
@@ -171,25 +186,15 @@
171 186 if ( $target_object['id'] === $origin_object['id'] ) {
172 187 return false;
173 188 }
174 189
175 - // Normalize alsoKnownAs to an array (some JSON-LD payloads may use a string).
176 - $also_known_as = (array) ( $target_object['alsoKnownAs'] ?? array() );
177 - if ( empty( $also_known_as ) ) {
190 + // Check if the target has an alsoKnownAs property.
191 + if ( empty( $target_object['also_known_as'] ) ) {
178 192 return false;
179 193 }
180 194
181 - // Collect all possible origin identifiers (id, url, webfinger).
182 - $origin_ids = \array_filter(
183 - array(
184 - $origin_object['id'] ?? null,
185 - $origin_object['url'] ?? null,
186 - $origin_object['webfinger'] ?? null,
187 - )
188 - );
189 -
190 - // Check if any origin identifier is in the alsoKnownAs property of the target.
191 - if ( ! \array_intersect( $origin_ids, $also_known_as ) ) {
195 + // Check if the origin is in the alsoKnownAs property of the target.
196 + if ( ! in_array( $origin_object['id'], $target_object['also_known_as'], true ) ) {
192 197 return false;
193 198 }
194 199
195 200 // Check if the origin has a movedTo property.