updated plugin Event Bridge for ActivityPub version 1.3.0

This commit is contained in:
2026-06-03 21:28:57 +00:00
committed by Gitium
parent 1f3438440f
commit f2d6714572
84 changed files with 1721 additions and 1361 deletions

View File

@ -13,7 +13,7 @@
namespace Event_Bridge_For_ActivityPub\ActivityPub\Model;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
\defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Actor;
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources;
@ -46,7 +46,7 @@ use WP_Post;
* @method array get_endpoints()
*/
class Event_Source extends Actor {
const ACTIVITYPUB_USER_HANDLE_REGEXP = '(?:([A-Za-z0-9_.-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))';
public const ACTIVITYPUB_USER_HANDLE_REGEXP = '(?:([A-Za-z0-9_.-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))';
/**
* The WordPress Post ID which stores the event source.
@ -133,7 +133,7 @@ class Event_Source extends Actor {
* @param string $activitypub_actor_id The ActivityPub actor ID.
* @return int|false The Event Sources Post ID, if a WordPress Post representing it is found, false otherwise.
*/
public static function get_post_id_by_activitypub_id( $activitypub_actor_id ) {
public static function get_post_id_by_activitypub_id( string $activitypub_actor_id ) {
$event_sources = Event_Sources::get_event_sources();
return array_search( $activitypub_actor_id, $event_sources, true );
@ -145,7 +145,7 @@ class Event_Source extends Actor {
* @param int|string $event_source_id The ActivityPub actor ID as string or the Post ID as int of the Event Source.
* @return ?Event_Source The Event Sources if it exists, false otherwise.
*/
public static function get_by_id( $event_source_id ): ?Event_Source {
public static function get_by_id( int|string $event_source_id ): ?Event_Source {
$post_id = is_integer( $event_source_id ) ? $event_source_id : self::get_post_id_by_activitypub_id( $event_source_id );
if ( ! $post_id ) {
@ -172,15 +172,21 @@ class Event_Source extends Actor {
/**
* Convert a Custom-Post-Type input to an \Event_Bridge_For_ActivityPub\ActivityPub\Model\Event_Source.
*
* @param \WP_Post $post The post object.
* @param WP_Post $post The post object.
* @return ?Event_Source
*/
public static function init_from_cpt( $post ): ?Event_Source {
public static function init_from_cpt( WP_Post $post ): ?Event_Source {
if ( Event_Sources::POST_TYPE !== $post->post_type ) {
return null;
}
$actor_json = \get_post_meta( $post->ID, '_activitypub_actor_json', true );
$object = static::init_from_json( $actor_json );
if ( empty( $post->post_content ) ) {
$actor_json = \get_post_meta( $post->ID, '_activitypub_actor_json', true );
} else {
$actor_json = $post->post_content;
}
$object = static::init_from_json( $actor_json );
if ( \is_wp_error( $object ) ) {
return null;
@ -202,10 +208,6 @@ class Event_Source extends Actor {
);
}
if ( ! $object instanceof Event_Source ) { // To make phpstan happy.
return null;
}
return $object;
}