@@ -21,7 +21,7 @@ class Delete {
2121 * Initialize the class, registering WordPress hooks.
2222 */
2323 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 );
2525 \add_filter ( 'activitypub_defer_signature_verification ' , array ( self ::class, 'defer_signature_verification ' ), 10 , 2 );
2626 \add_action ( 'activitypub_delete_actor_interactions ' , array ( self ::class, 'delete_interactions ' ) );
2727
@@ -33,9 +33,12 @@ public static function init() {
3333 * Handles "Delete" requests.
3434 *
3535 * @param array $activity The delete activity.
36+ * @param int $user_id The local user ID.
3637 */
37- public static function handle_delete ( $ activity ) {
38+ public static function handle_delete ( $ activity, $ user_id ) {
3839 $ object_type = $ activity ['object ' ]['type ' ] ?? '' ;
40+ $ success = false ;
41+ $ result = null ;
3942
4043 switch ( $ object_type ) {
4144 /*
@@ -48,7 +51,7 @@ public static function handle_delete( $activity ) {
4851 case 'Organization ' :
4952 case 'Service ' :
5053 case 'Application ' :
51- self ::maybe_delete_follower ( $ activity );
54+ $ result = self ::maybe_delete_follower ( $ activity );
5255 break ;
5356
5457 /*
@@ -63,7 +66,7 @@ public static function handle_delete( $activity ) {
6366 case 'Video ' :
6467 case 'Event ' :
6568 case 'Document ' :
66- self ::maybe_delete_interaction ( $ activity );
69+ $ result = self ::maybe_delete_interaction ( $ activity );
6770 break ;
6871
6972 /*
@@ -72,7 +75,7 @@ public static function handle_delete( $activity ) {
7275 * @see: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone
7376 */
7477 case 'Tombstone ' :
75- self ::maybe_delete_interaction ( $ activity );
78+ $ result = self ::maybe_delete_interaction ( $ activity );
7679 break ;
7780
7881 /*
@@ -88,34 +91,52 @@ public static function handle_delete( $activity ) {
8891
8992 // Check if Object is an Actor.
9093 if ( $ activity ['actor ' ] === $ activity ['object ' ] ) {
91- self ::maybe_delete_follower ( $ activity );
94+ $ result = self ::maybe_delete_follower ( $ activity );
9295 } else { // Assume an interaction otherwise.
93- self ::maybe_delete_interaction ( $ activity );
96+ $ result = self ::maybe_delete_interaction ( $ activity );
9497 }
9598 // Maybe handle Delete Activity for other Object Types.
9699 break ;
97100 }
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 );
98113 }
99114
100115 /**
101116 * Delete a Follower if Actor-URL is a Tombstone.
102117 *
103118 * @param array $activity The delete activity.
119+ *
120+ * @return bool True on success, false otherwise.
104121 */
105122 public static function maybe_delete_follower ( $ activity ) {
106123 $ follower = Remote_Actors::get_by_uri ( $ activity ['actor ' ] );
107124
108125 // Verify that Actor is deleted.
109126 if ( ! is_wp_error ( $ follower ) && Tombstone::exists ( $ activity ['actor ' ] ) ) {
110- Remote_Actors::delete ( $ follower ->ID );
127+ $ state = Remote_Actors::delete ( $ follower ->ID );
111128 self ::maybe_delete_interactions ( $ activity );
112129 }
130+
131+ return $ state ?? false ;
113132 }
114133
115134 /**
116135 * Delete Reactions if Actor-URL is a Tombstone.
117136 *
118137 * @param array $activity The delete activity.
138+ *
139+ * @return bool True on success, false otherwise.
119140 */
120141 public static function maybe_delete_interactions ( $ activity ) {
121142 // Verify that Actor is deleted.
@@ -125,26 +146,40 @@ public static function maybe_delete_interactions( $activity ) {
125146 'activitypub_delete_actor_interactions ' ,
126147 array ( $ activity ['actor ' ] )
127148 );
149+
150+ return true ;
128151 }
152+
153+ return false ;
129154 }
130155
131156 /**
132157 * Delete comments from an Actor.
133158 *
134159 * @param string $actor The URL of the actor whose comments to delete.
160+ *
161+ * @return bool True on success, false otherwise.
135162 */
136163 public static function delete_interactions ( $ actor ) {
137164 $ comments = Interactions::get_interactions_by_actor ( $ actor );
138165
139166 foreach ( $ comments as $ comment ) {
140167 wp_delete_comment ( $ comment , true );
141168 }
169+
170+ if ( $ comments ) {
171+ return true ;
172+ } else {
173+ return false ;
174+ }
142175 }
143176
144177 /**
145178 * Delete a Reaction if URL is a Tombstone.
146179 *
147180 * @param array $activity The delete activity.
181+ *
182+ * @return bool True on success, false otherwise.
148183 */
149184 public static function maybe_delete_interaction ( $ activity ) {
150185 if ( is_array ( $ activity ['object ' ] ) ) {
@@ -159,7 +194,11 @@ public static function maybe_delete_interaction( $activity ) {
159194 foreach ( $ comments as $ comment ) {
160195 wp_delete_comment ( $ comment ->comment_ID , true );
161196 }
197+
198+ return true ;
162199 }
200+
201+ return false ;
163202 }
164203
165204 /**
0 commit comments