# activitypub/3.2.3/includes/handler/class-like.php

ActivityPub, version 3.2.3. 60 lines.

- Page: https://pluginprobe.com/plugins/activitypub/3.2.3/code/includes/handler/class-like.php
- Raw: https://pluginprobe.com/plugins/activitypub/3.2.3/raw/includes/handler/class-like.php
- Modified: 2024-09-09T07:49:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/activitypub/3.2.3/code/includes/handler/class-like.php#L10-L20`.

```php
<?php
namespace Activitypub\Handler;

use Activitypub\Comment;
use Activitypub\Collection\Interactions;

use function Activitypub\object_to_uri;

/**
 * Handle Like requests
 */
class Like {
	/**
	 * Initialize the class, registering WordPress hooks
	 */
	public static function init() {
		\add_action(
			'activitypub_inbox_like',
			array( self::class, 'handle_like' ),
			10,
			3
		);
	}

	/**
	 * Handles "Like" requests
	 *
	 * @param array                 $array    The Activity array.
	 * @param int                   $user_id  The ID of the local blog user.
	 * @param \Activitypub\Activity $activity The Activity object.
	 *
	 * @return void
	 */
	public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
		if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
			return;
		}

		$url = object_to_uri( $array['object'] );

		if ( empty( $url ) ) {
			return;
		}

		$exists = Comment::object_id_to_comment( esc_url_raw( $url ) );
		if ( $exists ) {
			return;
		}

		$state    = Interactions::add_reaction( $array );
		$reaction = null;

		if ( $state && ! is_wp_error( $state ) ) {
			$reaction = get_comment( $state );
		}

		do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction );
	}
}

```
