PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.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-delete.php +14 -37 9.3.08.0.2 View file →
@@ -6,12 +6,11 @@
6 6 */
7 7
8 8 namespace Activitypub\Handler;
9 9
10 -use Activitypub\Collection\Inbox;
11 10 use Activitypub\Collection\Interactions;
11 +use Activitypub\Collection\Posts;
12 12 use Activitypub\Collection\Remote_Actors;
13 -use Activitypub\Collection\Remote_Posts;
14 13 use Activitypub\Tombstone;
15 14
16 15 use function Activitypub\object_to_uri;
17 16
@@ -22,12 +21,11 @@
22 21 /**
23 22 * Initialize the class, registering WordPress hooks.
24 23 */
25 24 public static function init() {
26 - \add_action( 'activitypub_inbox_delete', array( self::class, 'handle_delete' ), 10, 4 );
27 - \add_action( 'activitypub_inbox_shared_delete', array( self::class, 'handle_delete' ), 10, 4 );
25 + \add_action( 'activitypub_inbox_delete', array( self::class, 'handle_delete' ), 10, 2 );
28 26 \add_filter( 'activitypub_skip_inbox_storage', array( self::class, 'skip_inbox_storage' ), 10, 2 );
29 - \add_filter( 'activitypub_defer_signature_verification', array( self::class, 'defer_signature_verification' ), 10, 3 );
27 + \add_filter( 'activitypub_defer_signature_verification', array( self::class, 'defer_signature_verification' ), 10, 2 );
30 28 \add_action( 'activitypub_delete_remote_actor_interactions', array( self::class, 'delete_interactions' ) );
31 29 \add_action( 'activitypub_delete_remote_actor_posts', array( self::class, 'delete_posts' ) );
32 30
33 31 \add_filter( 'activitypub_get_outbox_activity', array( self::class, 'outbox_activity' ) );
@@ -36,20 +34,12 @@
36 34
37 35 /**
38 36 * Handles "Delete" requests.
39 37 *
40 - * @param array $activity The delete activity.
41 - * @param int|int[] $user_ids The local user ID(s).
42 - * @param \Activitypub\Activity\Activity|null $activity_object Optional. The activity object. Default null.
43 - * @param string|null $context Optional. The inbox context. Default null.
38 + * @param array $activity The delete activity.
39 + * @param int|int[] $user_ids The local user ID(s).
44 40 */
45 - public static function handle_delete( $activity, $user_ids, $activity_object = null, $context = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
46 - // The shared inbox invokes this once per resolved recipient and once on the shared hook;
47 - // handle that path only on the shared hook, so it runs once with the full recipient list.
48 - if ( Inbox::CONTEXT_SHARED_INBOX === $context && 'activitypub_inbox_shared_delete' !== \current_filter() ) {
49 - return;
50 - }
51 -
41 + public static function handle_delete( $activity, $user_ids ) {
52 42 $object_type = $activity['object']['type'] ?? '';
53 43
54 44 switch ( $object_type ) {
55 45 /*
@@ -165,9 +155,9 @@
165 155 public static function maybe_delete_follower( $activity ) {
166 156 $follower = Remote_Actors::get_by_uri( $activity['actor'] );
167 157
168 158 // Verify that Actor is deleted.
169 - if ( ! \is_wp_error( $follower ) && Tombstone::exists( $activity['actor'] ) ) {
159 + if ( ! is_wp_error( $follower ) && Tombstone::exists( $activity['actor'] ) ) {
170 160 self::maybe_delete_interactions( $follower->ID );
171 161 self::maybe_delete_posts( $follower->ID );
172 162 $state = Remote_Actors::delete( $follower->ID );
173 163 }
@@ -229,12 +219,12 @@
229 219 *
230 220 * @return bool True on success, false otherwise.
231 221 */
232 222 public static function delete_posts( $id ) {
233 - $posts = Remote_Posts::get_by_remote_actor_id( $id );
223 + $posts = Posts::get_by_remote_actor_id( $id );
234 224
235 225 foreach ( $posts as $post ) {
236 - Remote_Posts::delete( $post->ID );
226 + Posts::delete( $post->ID );
237 227 }
238 228
239 229 if ( $posts ) {
240 230 return true;
@@ -261,9 +251,9 @@
261 251
262 252 if ( $comments && Tombstone::exists( $id ) ) {
263 253 foreach ( $comments as $comment ) {
264 254 // WordPress will automatically delete all comment meta including _activitypub_remote_actor_id.
265 - \wp_delete_comment( $comment->comment_ID, true );
255 + wp_delete_comment( $comment->comment_ID, true );
266 256 }
267 257
268 258 return true;
269 259 }
@@ -282,9 +272,9 @@
282 272 $id = object_to_uri( $activity['object'] );
283 273
284 274 // Check if the object exists and is a tombstone.
285 275 if ( Tombstone::exists( $id ) ) {
286 - return Remote_Posts::delete_by_guid( $id );
276 + return Posts::delete_by_guid( $id );
287 277 }
288 278
289 279 return false;
290 280 }
@@ -307,27 +297,14 @@
307 297
308 298 /**
309 299 * Defer signature verification for `Delete` requests.
310 300 *
311 - * Endpoints that opt in to mandatory signing by calling
312 - * `verify_signature( $request, true )` must not be overridden — the
313 - * Delete carve-out is only for the default inbox path where the
314 - * remote actor's keys may legitimately be gone before the Delete
315 - * arrives.
301 + * @param bool $defer Whether to defer signature verification.
302 + * @param \WP_REST_Request $request The request object.
316 303 *
317 - * @since 8.2.0 The `$force_signature` parameter is now respected.
318 - *
319 - * @param bool $defer Whether to defer signature verification.
320 - * @param \WP_REST_Request $request The request object.
321 - * @param bool $force_signature Whether the caller has forced signature verification.
322 - *
323 304 * @return bool Whether to defer signature verification.
324 305 */
325 - public static function defer_signature_verification( $defer, $request, $force_signature = false ) {
326 - if ( $force_signature ) {
327 - return $defer;
328 - }
329 -
306 + public static function defer_signature_verification( $defer, $request ) {
330 307 $json = $request->get_json_params();
331 308
332 309 if ( isset( $json['type'] ) && 'Delete' === $json['type'] ) {
333 310 return true;