PluginProbe
ActivityPub / 4.3.0
ActivityPub v4.3.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
activitypub / includes / handler / class-like.php

class-like.php in ActivityPub 4.3.0, at includes/handler/class-like.php

71 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Like handler file.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\Handler;
9
10 use Activitypub\Comment;
11 use Activitypub\Collection\Interactions;
12
13 use function Activitypub\object_to_uri;
14
15 /**
16 * Handle Like requests.
17 */
18 class Like {
19 /**
20 * Initialize the class, registering WordPress hooks.
21 */
22 public static function init() {
23 \add_action(
24 'activitypub_inbox_like',
25 array( self::class, 'handle_like' ),
26 10,
27 3
28 );
29 }
30
31 /**
32 * Handles "Like" requests.
33 *
34 * @param array $like The Activity array.
35 * @param int $user_id The ID of the local blog user.
36 */
37 public static function handle_like( $like, $user_id ) {
38 if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
39 return;
40 }
41
42 $url = object_to_uri( $like['object'] );
43
44 if ( empty( $url ) ) {
45 return;
46 }
47
48 $exists = Comment::object_id_to_comment( esc_url_raw( $url ) );
49 if ( $exists ) {
50 return;
51 }
52
53 $state = Interactions::add_reaction( $like );
54 $reaction = null;
55
56 if ( $state && ! is_wp_error( $state ) ) {
57 $reaction = get_comment( $state );
58 }
59
60 /**
61 * Fires after a Like has been handled.
62 *
63 * @param array $like The Activity array.
64 * @param int $user_id The ID of the local blog user.
65 * @param mixed $state The state of the reaction.
66 * @param mixed $reaction The reaction object.
67 */
68 do_action( 'activitypub_handled_like', $like, $user_id, $state, $reaction );
69 }
70 }
71