PluginProbe
ActivityPub / 3.2.5
ActivityPub v3.2.5
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-undo.php +34 -6 2.1.03.2.5 View file →
@@ -2,9 +2,12 @@
2 2 namespace Activitypub\Handler;
3 3
4 4 use Activitypub\Collection\Users;
5 5 use Activitypub\Collection\Followers;
6 +use Activitypub\Comment;
6 7
8 +use function Activitypub\object_to_uri;
9 +
7 10 /**
8 11 * Handle Undo requests
9 12 */
10 13 class Undo {
@@ -25,15 +28,21 @@
25 28 * @param int $user_id The ID of the ID of the WordPress User
26 29 */
27 30 public static function handle_undo( $activity ) {
28 31 if (
29 - isset( $activity['object']['type'] ) &&
30 - 'Follow' === $activity['object']['type'] &&
31 - isset( $activity['object']['object'] ) &&
32 - filter_var( $activity['object']['object'], FILTER_VALIDATE_URL )
32 + ! isset( $activity['object']['type'] ) ||
33 + ! isset( $activity['object']['object'] )
33 34 ) {
34 - $user = Users::get_by_resource( $activity['object']['object'] );
35 + return;
36 + }
35 37
38 + $type = $activity['object']['type'];
39 +
40 + // Handle "Unfollow" requests
41 + if ( 'Follow' === $type ) {
42 + $user_id = object_to_uri( $activity['object']['object'] );
43 + $user = Users::get_by_resource( $user_id );
44 +
36 45 if ( ! $user || is_wp_error( $user ) ) {
37 46 // If we can not find a user,
38 47 // we can not initiate a follow process
39 48 return;
@@ -39,9 +48,28 @@
39 48 return;
40 49 }
41 50
42 51 $user_id = $user->get__id();
52 + $actor = object_to_uri( $activity['actor'] );
43 53
44 - Followers::remove_follower( $user_id, $activity['actor'] );
54 + Followers::remove_follower( $user_id, $actor );
55 + }
56 +
57 + // Handle "Undo" requests for "Like" and "Create" activities
58 + if ( in_array( $type, array( 'Like', 'Create', 'Announce' ), true ) ) {
59 + if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
60 + return;
61 + }
62 +
63 + $object_id = object_to_uri( $activity['object'] );
64 + $comment = Comment::object_id_to_comment( esc_url_raw( $object_id ) );
65 +
66 + if ( empty( $comment ) ) {
67 + return;
68 + }
69 +
70 + $state = wp_trash_comment( $comment );
71 +
72 + do_action( 'activitypub_handled_undo', $activity, $user_id, isset( $state ) ? $state : null, null );
45 73 }
46 74 }
47 75 }