get_error_code() ) { $updated = false; } } // There is no object to update, try to trigger create instead. if ( ! $updated ) { return Create::handle_create( $activity, $user_ids, $activity_object ); } $success = ( $result && ! \is_wp_error( $result ) ); /** * Fires after an ActivityPub Update activity has been handled. * * @param array $activity The ActivityPub activity data. * @param int[]|null $user_ids The local user IDs. * @param bool $success True on success, false otherwise. * @param \WP_Comment|\WP_Post|\WP_Error $result The updated post, comment, or error. */ \do_action( 'activitypub_handled_update', $activity, (array) $user_ids, $success, $result ); } /** * Update an Actor. * * @param array $activity The Activity object. * @param int[]|null $user_ids The user IDs. Always null for Update activities. */ public static function update_actor( $activity, $user_ids ) { /* * Prefer the actor data embedded in the activity object, as it contains * the fresh data sent by the remote server. */ $actor = $activity['object'] ?? null; /* * The object may be a string IRI instead of an embedded object, * in which case we need to fetch the actor data remotely. * We use Http::get_remote_object() directly instead of * get_remote_metadata_by_actor() because the latter returns the * stale locally cached copy via fetch_by_uri(). */ if ( ! \is_array( $actor ) || ! isset( $actor['id'] ) ) { $object = Http::get_remote_object( $activity['actor'], false ); if ( ! \is_wp_error( $object ) && \is_array( $object ) ) { $actor = $object; } } if ( \is_array( $actor ) && isset( $actor['id'] ) ) { $state = Remote_Actors::upsert( $actor ); } else { $state = new \WP_Error( 'activitypub_update_failed', 'Update failed: missing or invalid actor object in Update activity' ); $actor = array(); } /** * Fires after an ActivityPub Update activity has been handled. * * @param array $activity The ActivityPub activity data. * @param int[] $user_ids The local user IDs. * @param int|\WP_Error $state Actor post ID on success, WP_Error on failure. * @param array $actor Remote actor meta data. */ \do_action( 'activitypub_handled_update', $activity, (array) $user_ids, $state, $actor ); } }