PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.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
← All changes | includes/class-move.php +14 -20 9.2.05.7.0 View file →
@@ -6,10 +6,10 @@
6 6 */
7 7
8 8 namespace Activitypub;
9 9
10 +use Activitypub\Activity\Actor;
10 11 use Activitypub\Activity\Activity;
11 -use Activitypub\Activity\Actor;
12 12 use Activitypub\Collection\Actors;
13 13 use Activitypub\Model\Blog;
14 14 use Activitypub\Model\User;
15 15
@@ -28,15 +28,15 @@
28 28 * Filter to enable automatically moving Fediverse accounts when the domain changes.
29 29 *
30 30 * @param bool $domain_moves_enabled Whether domain moves are enabled.
31 31 */
32 - $domain_moves_enabled = \apply_filters( 'activitypub_enable_primary_domain_moves', false );
32 + $domain_moves_enabled = apply_filters( 'activitypub_enable_primary_domain_moves', false );
33 33
34 34 if ( $domain_moves_enabled ) {
35 35 // Add the filter to change the domain.
36 36 \add_filter( 'update_option_home', array( self::class, 'change_domain' ), 10, 2 );
37 37
38 - if ( \get_option( 'activitypub_old_host' ) ) {
38 + if ( get_option( 'activitypub_old_host' ) ) {
39 39 \add_action( 'activitypub_construct_model_actor', array( self::class, 'maybe_initiate_old_user' ) );
40 40 \add_action( 'activitypub_pre_send_to_inboxes', array( self::class, 'pre_send_to_inboxes' ) );
41 41
42 42 if ( ! is_user_type_disabled( 'blog' ) ) {
@@ -64,9 +64,9 @@
64 64
65 65 /**
66 66 * Move an ActivityPub Actor from one location (internal) to another (external).
67 67 *
68 - * This helps with migrating local profiles to a new external profile:
68 + * This helps migrating local profiles to a new external profile:
69 69 *
70 70 * `Move::externally( 'https://example.com/?author=123', 'https://mastodon.example/users/foo' );`
71 71 *
72 72 * @param string $from The current account URL.
@@ -98,10 +98,10 @@
98 98 $target_actor->from_array( $response );
99 99
100 100 // Check if the `Move` Activity is valid.
101 101 $also_known_as = $target_actor->get_also_known_as() ?? array();
102 - if ( ! \in_array( $from, $also_known_as, true ) ) {
103 - return new \WP_Error( 'invalid_target', \__( 'Invalid target', 'activitypub' ) );
102 + if ( ! in_array( $from, $also_known_as, true ) ) {
103 + return new \WP_Error( 'invalid_target', __( 'Invalid target', 'activitypub' ) );
104 104 }
105 105
106 106 $activity = new Activity();
107 107 $activity->set_type( 'Move' );
@@ -118,9 +118,9 @@
118 118 * Internal Move.
119 119 *
120 120 * Move an ActivityPub Actor from one location (internal) to another (internal).
121 121 *
122 - * This helps with migrating abandoned profiles to `Move` to other profiles:
122 + * This helps migrating abandoned profiles to `Move` to other profiles:
123 123 *
124 124 * `Move::internally( 'https://example.com/?author=123', 'https://example.com/?author=321' );`
125 125 *
126 126 * ... or to change Actor-IDs like:
@@ -171,8 +171,9 @@
171 171 * @param int $user_id The user ID.
172 172 * @param string $from The current account URL.
173 173 */
174 174 private static function update_user_also_known_as( $user_id, $from ) {
175 + // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
175 176 $also_known_as = \get_user_option( 'activitypub_also_known_as', $user_id ) ?: array();
176 177 $also_known_as[] = $from;
177 178
178 179 \update_user_option( $user_id, 'activitypub_also_known_as', $also_known_as );
@@ -217,33 +218,26 @@
217 218 foreach ( $actors as $actor ) {
218 219 $actor_id = $actor->get_id();
219 220
220 221 // Replace the new host with the old host in the actor ID.
221 - $old_actor_id = \str_replace( $to_host, $from_host, $actor_id );
222 + $old_actor_id = str_replace( $to_host, $from_host, $actor_id );
222 223
223 224 // Call Move::internally for this actor.
224 225 $result = self::internally( $old_actor_id, $actor_id );
225 226
226 227 if ( \is_wp_error( $result ) ) {
227 - /**
228 - * Fires when an actor move fails during domain change.
229 - *
230 - * @since 8.1.0
231 - *
232 - * @param \WP_Error $result The error that occurred.
233 - * @param string $actor_id The actor ID that failed to move.
234 - */
235 - \do_action( 'activitypub_move_failed', $result, $actor_id );
228 + // Log the error and continue with the next actor.
229 + Debug::write_log( 'Error moving actor: ' . $actor_id . ' - ' . $result->get_error_message() );
236 230 continue;
237 231 }
238 232
239 - $json = \str_replace( $to_host, $from_host, $actor->to_json() );
233 + $json = str_replace( $to_host, $from_host, $actor->to_json() );
240 234
241 235 // Save the current actor data after migration.
242 236 if ( $actor instanceof Blog ) {
243 237 \update_option( 'activitypub_blog_user_old_host_data', $json, false );
244 238 } else {
245 - \update_user_option( $actor->get__id(), 'activitypub_old_host_data', $json );
239 + \update_user_option( $actor->get__id(), 'activitypub_old_host_data', $json, false );
246 240 }
247 241
248 242 $results[] = array(
249 243 'actor' => $actor_id,
@@ -283,9 +277,9 @@
283 277 *
284 278 * @param string $json The ActivityPub Activity JSON.
285 279 */
286 280 public static function pre_send_to_inboxes( $json ) {
287 - $json = \json_decode( $json, true );
281 + $json = json_decode( $json, true );
288 282
289 283 if ( 'Move' !== $json['type'] ) {
290 284 return;
291 285 }