PluginProbe
ActivityPub / 5.1.0
ActivityPub v5.1.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/handler/class-delete.php +41 -24 2.0.05.1.0 View file →
@@ -1,8 +1,13 @@
1 1 <?php
2 +/**
3 + * Delete handler file.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub\Handler;
3 9
4 -use WP_Error;
5 10 use WP_REST_Request;
6 11 use Activitypub\Http;
7 12 use Activitypub\Collection\Followers;
8 13 use Activitypub\Collection\Interactions;
@@ -11,9 +16,9 @@
11 16 * Handles Delete requests.
12 17 */
13 18 class Delete {
14 19 /**
15 - * Initialize the class, registering WordPress hooks
20 + * Initialize the class, registering WordPress hooks.
16 21 */
17 22 public static function init() {
18 23 \add_action(
19 24 'activitypub_inbox_delete',
@@ -19,9 +24,9 @@
19 24 'activitypub_inbox_delete',
20 25 array( self::class, 'handle_delete' )
21 26 );
22 27
23 - // defer signature verification for `Delete` requests.
28 + // Defer signature verification for `Delete` requests.
24 29 \add_filter(
25 30 'activitypub_defer_signature_verification',
26 31 array( self::class, 'defer_signature_verification' ),
27 32 10,
@@ -27,9 +32,9 @@
27 32 10,
28 33 2
29 34 );
30 35
31 - // side effect
36 + // Side effect.
32 37 \add_action(
33 38 'activitypub_delete_actor_interactions',
34 39 array( self::class, 'delete_interactions' )
35 40 );
@@ -38,16 +43,18 @@
38 43 /**
39 44 * Handles "Delete" requests.
40 45 *
41 46 * @param array $activity The delete activity.
42 - * @param int $user_id The ID of the user performing the delete activity.
43 47 */
44 48 public static function handle_delete( $activity ) {
45 49 $object_type = isset( $activity['object']['type'] ) ? $activity['object']['type'] : '';
46 50
47 51 switch ( $object_type ) {
48 - // Actor Types
49 - // @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
52 + /*
53 + * Actor Types.
54 + *
55 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#actor-types
56 + */
50 57 case 'Person':
51 58 case 'Group':
52 59 case 'Organization':
53 60 case 'Service':
@@ -53,10 +60,14 @@
53 60 case 'Service':
54 61 case 'Application':
55 62 self::maybe_delete_follower( $activity );
56 63 break;
57 - // Object and Link Types
58 - // @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
64 +
65 + /*
66 + * Object and Link Types.
67 + *
68 + * @see https://www.w3.org/TR/activitystreams-vocabulary/#object-types
69 + */
59 70 case 'Note':
60 71 case 'Article':
61 72 case 'Image':
62 73 case 'Audio':
@@ -64,29 +75,36 @@
64 75 case 'Event':
65 76 case 'Document':
66 77 self::maybe_delete_interaction( $activity );
67 78 break;
68 - // Tombstone Type
69 - // @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone
79 +
80 + /*
81 + * Tombstone Type.
82 + *
83 + * @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone
84 + */
70 85 case 'Tombstone':
71 86 self::maybe_delete_interaction( $activity );
72 87 break;
73 - // Minimal Activity
74 - // @see https://www.w3.org/TR/activitystreams-core/#example-1
88 +
89 + /*
90 + * Minimal Activity.
91 + *
92 + * @see https://www.w3.org/TR/activitystreams-core/#example-1
93 + */
75 94 default:
76 - // ignore non Minimal Activities.
95 + // Ignore non Minimal Activities.
77 96 if ( ! is_string( $activity['object'] ) ) {
78 97 return;
79 98 }
80 99
81 - // check if Object is an Actor.
100 + // Check if Object is an Actor.
82 101 if ( $activity['actor'] === $activity['object'] ) {
83 102 self::maybe_delete_follower( $activity );
84 - self::maybe_delete_interactions( $activity );
85 - } else { // assume a interaction otherwise.
103 + } else { // Assume an interaction otherwise.
86 104 self::maybe_delete_interaction( $activity );
87 105 }
88 - // maybe handle Delete Activity for other Object Types.
106 + // Maybe handle Delete Activity for other Object Types.
89 107 break;
90 108 }
91 109 }
92 110
@@ -97,11 +115,12 @@
97 115 */
98 116 public static function maybe_delete_follower( $activity ) {
99 117 $follower = Followers::get_follower_by_actor( $activity['actor'] );
100 118
101 - // verify if Actor is deleted.
119 + // Verify that Actor is deleted.
102 120 if ( $follower && Http::is_tombstone( $activity['actor'] ) ) {
103 121 $follower->delete();
122 + self::maybe_delete_interactions( $activity );
104 123 }
105 124 }
106 125
107 126 /**
@@ -109,9 +128,9 @@
109 128 *
110 129 * @param array $activity The delete activity.
111 130 */
112 131 public static function maybe_delete_interactions( $activity ) {
113 - // verify if Actor is deleted.
132 + // Verify that Actor is deleted.
114 133 if ( Http::is_tombstone( $activity['actor'] ) ) {
115 134 \wp_schedule_single_event(
116 135 \time(),
117 136 'activitypub_delete_actor_interactions',
@@ -122,9 +141,9 @@
122 141
123 142 /**
124 143 * Delete comments from an Actor.
125 144 *
126 - * @param array $comments The comments to delete.
145 + * @param array $actor The actor whose comments to delete.
127 146 */
128 147 public static function delete_interactions( $actor ) {
129 148 $comments = Interactions::get_interactions_by_actor( $actor );
130 149
@@ -129,9 +148,9 @@
129 148 $comments = Interactions::get_interactions_by_actor( $actor );
130 149
131 150 if ( is_array( $comments ) ) {
132 151 foreach ( $comments as $comment ) {
133 - wp_delete_comment( $comment->comment_ID );
152 + wp_delete_comment( $comment->comment_ID, true );
134 153 }
135 154 }
136 155 }
137 156
@@ -138,10 +157,8 @@
138 157 /**
139 158 * Delete a Reaction if URL is a Tombstone.
140 159 *
141 160 * @param array $activity The delete activity.
142 - *
143 - * @return void
144 161 */
145 162 public static function maybe_delete_interaction( $activity ) {
146 163 if ( is_array( $activity['object'] ) ) {
147 164 $id = $activity['object']['id'];