# activitypub/2.5.0/includes/handler/class-announce.php

ActivityPub, version 2.5.0. 70 lines.

- Page: https://pluginprobe.com/plugins/activitypub/2.5.0/code/includes/handler/class-announce.php
- Raw: https://pluginprobe.com/plugins/activitypub/2.5.0/raw/includes/handler/class-announce.php
- Modified: 2024-06-05T13:38:00+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/2.5.0/code/includes/handler/class-announce.php#L10-L20`.

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

use Activitypub\Http;

use function Activitypub\is_activity_public;

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

	/**
	 * Handles "Announce" requests
	 *
	 * @param array                $array    The activity-object
	 * @param int                  $user_id  The id of the local blog-user
	 * @param Activitypub\Activity $activity The activity object
	 *
	 * @return void
	 */
	public static function handle_announce( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
		if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
			return;
		}

		if ( ! isset( $array['object'] ) ) {
			return;
		}

		// check if Activity is public or not
		if ( ! is_activity_public( $array ) ) {
			// @todo maybe send email
			return;
		}

		// @todo save the `Announce`-Activity itself

		if ( is_string( $array['object'] ) ) {
			$object = Http::get_remote_object( $array['object'] );
		} else {
			$object = $array['object'];
		}

		if ( ! $object || is_wp_error( $object ) ) {
			return;
		}

		if ( ! isset( $object['type'] ) ) {
			return;
		}

		$type = \strtolower( $object['type'] );

		\do_action( 'activitypub_inbox', $object, $user_id, $type, $activity );
		\do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity );
	}
}

```
