PluginProbe
ActivityPub / 3.2.2
ActivityPub v3.2.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-like.php +24 -52 9.2.03.2.2 View file →
@@ -1,87 +1,59 @@
1 1 <?php
2 -/**
3 - * Like handler file.
4 - *
5 - * @package Activitypub
6 - */
7 -
8 2 namespace Activitypub\Handler;
9 3
4 +use Activitypub\Comment;
10 5 use Activitypub\Collection\Interactions;
11 -use Activitypub\Comment;
12 6
13 7 use function Activitypub\object_to_uri;
14 8
15 9 /**
16 - * Handle Like requests.
10 + * Handle Like requests
17 11 */
18 12 class Like {
19 13 /**
20 - * Initialize the class, registering WordPress hooks.
14 + * Initialize the class, registering WordPress hooks
21 15 */
22 16 public static function init() {
23 - \add_action( 'activitypub_inbox_like', array( self::class, 'handle_like' ), 10, 2 );
24 - \add_filter( 'activitypub_get_outbox_activity', array( self::class, 'outbox_activity' ) );
17 + \add_action(
18 + 'activitypub_inbox_like',
19 + array( self::class, 'handle_like' ),
20 + 10,
21 + 3
22 + );
25 23 }
26 24
27 25 /**
28 - * Handles "Like" requests.
26 + * Handles "Like" requests
29 27 *
30 - * @param array $like The Activity array.
31 - * @param int|int[] $user_ids The user ID(s).
28 + * @param array $array The Activity array.
29 + * @param int $user_id The ID of the local blog user.
30 + * @param \Activitypub\Activity $activity The Activity object.
31 + *
32 + * @return void
32 33 */
33 - public static function handle_like( $like, $user_ids ) {
34 - if ( ! Comment::is_comment_type_enabled( 'like' ) ) {
34 + public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
35 + if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
35 36 return;
36 37 }
37 38
38 - $url = object_to_uri( $like['object'] );
39 + $url = object_to_uri( $array['object'] );
39 40
40 41 if ( empty( $url ) ) {
41 42 return;
42 43 }
43 44
44 - /*
45 - * Dedupe on the Like activity ID (its source_id), not the liked object, so repeat
46 - * deliveries stay idempotent even when a mangled author name defeats WordPress's own
47 - * duplicate check. Match any status, so a like that was marked as spam or trashed
48 - * still counts as seen. See https://github.com/Automattic/wordpress-activitypub/issues/3215.
49 - */
50 - $exists = Comment::object_id_to_comment( \esc_url_raw( object_to_uri( $like ) ), array( 'status' => 'any' ) );
45 + $exists = Comment::object_id_to_comment( esc_url_raw( $url ) );
51 46 if ( $exists ) {
52 47 return;
53 48 }
54 49
55 - $success = false;
56 - $result = Interactions::add_reaction( $like );
50 + $state = Interactions::add_reaction( $array );
51 + $reaction = null;
57 52
58 - if ( $result && ! \is_wp_error( $result ) ) {
59 - $success = true;
60 - $result = \get_comment( $result );
53 + if ( $state && ! is_wp_error( $state ) ) {
54 + $reaction = get_comment( $state );
61 55 }
62 56
63 - /**
64 - * Fires after an ActivityPub Like activity has been handled.
65 - *
66 - * @param array $like The ActivityPub activity data.
67 - * @param int[] $user_ids The local user IDs.
68 - * @param bool $success True on success, false otherwise.
69 - * @param array|false|int|string|\WP_Comment|\WP_Error $result The WP_Comment object of the created like comment, or null if creation failed.
70 - */
71 - \do_action( 'activitypub_handled_like', $like, (array) $user_ids, $success, $result );
72 - }
73 -
74 - /**
75 - * Set the object to the object ID.
76 - *
77 - * @param \Activitypub\Activity\Activity $activity The Activity object.
78 - * @return \Activitypub\Activity\Activity The filtered Activity object.
79 - */
80 - public static function outbox_activity( $activity ) {
81 - if ( 'Like' === $activity->get_type() ) {
82 - $activity->set_object( object_to_uri( $activity->get_object() ) );
83 - }
84 -
85 - return $activity;
57 + do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction );
86 58 }
87 59 }