@@ -21,7 +21,7 @@ class Delete {
21
21
* Initialize the class, registering WordPress hooks.
22
22
*/
23
23
public static function init () {
24
- \add_action ( 'activitypub_inbox_delete ' , array ( self ::class, 'handle_delete ' ) );
24
+ \add_action ( 'activitypub_inbox_delete ' , array ( self ::class, 'handle_delete ' ), 10 , 2 );
25
25
\add_filter ( 'activitypub_defer_signature_verification ' , array ( self ::class, 'defer_signature_verification ' ), 10 , 2 );
26
26
\add_action ( 'activitypub_delete_actor_interactions ' , array ( self ::class, 'delete_interactions ' ) );
27
27
@@ -33,9 +33,12 @@ public static function init() {
33
33
* Handles "Delete" requests.
34
34
*
35
35
* @param array $activity The delete activity.
36
+ * @param int $user_id The local user ID.
36
37
*/
37
- public static function handle_delete ( $ activity ) {
38
+ public static function handle_delete ( $ activity, $ user_id ) {
38
39
$ object_type = $ activity ['object ' ]['type ' ] ?? '' ;
40
+ $ success = false ;
41
+ $ result = null ;
39
42
40
43
switch ( $ object_type ) {
41
44
/*
@@ -48,7 +51,7 @@ public static function handle_delete( $activity ) {
48
51
case 'Organization ' :
49
52
case 'Service ' :
50
53
case 'Application ' :
51
- self ::maybe_delete_follower ( $ activity );
54
+ $ result = self ::maybe_delete_follower ( $ activity );
52
55
break ;
53
56
54
57
/*
@@ -63,7 +66,7 @@ public static function handle_delete( $activity ) {
63
66
case 'Video ' :
64
67
case 'Event ' :
65
68
case 'Document ' :
66
- self ::maybe_delete_interaction ( $ activity );
69
+ $ result = self ::maybe_delete_interaction ( $ activity );
67
70
break ;
68
71
69
72
/*
@@ -72,7 +75,7 @@ public static function handle_delete( $activity ) {
72
75
* @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone
73
76
*/
74
77
case 'Tombstone ' :
75
- self ::maybe_delete_interaction ( $ activity );
78
+ $ result = self ::maybe_delete_interaction ( $ activity );
76
79
break ;
77
80
78
81
/*
@@ -88,34 +91,52 @@ public static function handle_delete( $activity ) {
88
91
89
92
// Check if Object is an Actor.
90
93
if ( $ activity ['actor ' ] === $ activity ['object ' ] ) {
91
- self ::maybe_delete_follower ( $ activity );
94
+ $ result = self ::maybe_delete_follower ( $ activity );
92
95
} else { // Assume an interaction otherwise.
93
- self ::maybe_delete_interaction ( $ activity );
96
+ $ result = self ::maybe_delete_interaction ( $ activity );
94
97
}
95
98
// Maybe handle Delete Activity for other Object Types.
96
99
break ;
97
100
}
101
+
102
+ $ success = (bool ) $ result ;
103
+
104
+ /**
105
+ * Fires after an ActivityPub Delete activity has been handled.
106
+ *
107
+ * @param array $activity The ActivityPub activity data.
108
+ * @param int $user_id The local user ID.
109
+ * @param bool $success True on success, false otherwise.
110
+ * @param mixed|null $result The result of the delete operation (e.g., WP_Comment object or deletion status).
111
+ */
112
+ \do_action ( 'activitypub_handled_delete ' , $ activity , $ user_id , $ success , $ result );
98
113
}
99
114
100
115
/**
101
116
* Delete a Follower if Actor-URL is a Tombstone.
102
117
*
103
118
* @param array $activity The delete activity.
119
+ *
120
+ * @return bool True on success, false otherwise.
104
121
*/
105
122
public static function maybe_delete_follower ( $ activity ) {
106
123
$ follower = Remote_Actors::get_by_uri ( $ activity ['actor ' ] );
107
124
108
125
// Verify that Actor is deleted.
109
126
if ( ! is_wp_error ( $ follower ) && Tombstone::exists ( $ activity ['actor ' ] ) ) {
110
- Remote_Actors::delete ( $ follower ->ID );
127
+ $ state = Remote_Actors::delete ( $ follower ->ID );
111
128
self ::maybe_delete_interactions ( $ activity );
112
129
}
130
+
131
+ return $ state ?? false ;
113
132
}
114
133
115
134
/**
116
135
* Delete Reactions if Actor-URL is a Tombstone.
117
136
*
118
137
* @param array $activity The delete activity.
138
+ *
139
+ * @return bool True on success, false otherwise.
119
140
*/
120
141
public static function maybe_delete_interactions ( $ activity ) {
121
142
// Verify that Actor is deleted.
@@ -125,26 +146,40 @@ public static function maybe_delete_interactions( $activity ) {
125
146
'activitypub_delete_actor_interactions ' ,
126
147
array ( $ activity ['actor ' ] )
127
148
);
149
+
150
+ return true ;
128
151
}
152
+
153
+ return false ;
129
154
}
130
155
131
156
/**
132
157
* Delete comments from an Actor.
133
158
*
134
159
* @param string $actor The URL of the actor whose comments to delete.
160
+ *
161
+ * @return bool True on success, false otherwise.
135
162
*/
136
163
public static function delete_interactions ( $ actor ) {
137
164
$ comments = Interactions::get_interactions_by_actor ( $ actor );
138
165
139
166
foreach ( $ comments as $ comment ) {
140
167
wp_delete_comment ( $ comment , true );
141
168
}
169
+
170
+ if ( $ comments ) {
171
+ return true ;
172
+ } else {
173
+ return false ;
174
+ }
142
175
}
143
176
144
177
/**
145
178
* Delete a Reaction if URL is a Tombstone.
146
179
*
147
180
* @param array $activity The delete activity.
181
+ *
182
+ * @return bool True on success, false otherwise.
148
183
*/
149
184
public static function maybe_delete_interaction ( $ activity ) {
150
185
if ( is_array ( $ activity ['object ' ] ) ) {
@@ -159,7 +194,11 @@ public static function maybe_delete_interaction( $activity ) {
159
194
foreach ( $ comments as $ comment ) {
160
195
wp_delete_comment ( $ comment ->comment_ID , true );
161
196
}
197
+
198
+ return true ;
162
199
}
200
+
201
+ return false ;
163
202
}
164
203
165
204
/**
0 commit comments