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,10 +13,9 @@
namespace Event_Bridge_For_ActivityPub;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
\defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection;
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Join as Join_Handler;
use Event_Bridge_For_ActivityPub\ActivityPub\Scheduler\Event as Event_Scheduler;
use Event_Bridge_For_ActivityPub\Admin\Event_Plugin_Admin_Notices;
use Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices;
@ -25,10 +24,14 @@ use Event_Bridge_For_ActivityPub\Admin\Settings_Page;
use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin_Integration;
use Event_Bridge_For_ActivityPub\Integrations\Feature_Event_Sources;
use Event_Bridge_For_ActivityPub\Reminder;
use WP_Comment;
use WP_Post;
use WP_Post_Type;
use WP_User;
use WP_Term;
use function Activitypub\is_user_type_disabled;
// @phpstan-ignore-next-line
require_once ABSPATH . 'wp-admin/includes/plugin.php';
/**
@ -39,13 +42,6 @@ require_once ABSPATH . 'wp-admin/includes/plugin.php';
* @since 1.0.0
*/
class Setup {
/**
* Keep the information whether the ActivityPub plugin is active.
*
* @var boolean
*/
protected $activitypub_plugin_is_active = false;
/**
* Keep the current version of the current ActivityPub plugin.
*
@ -68,9 +64,8 @@ class Setup {
* @since 1.0.0
*/
protected function __construct() {
// Detect the presence/active-status and version of the ActivityPub plugin.
$this->activitypub_plugin_is_active = defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) || \is_plugin_active( 'activitypub/activitypub.php' );
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
// Detect the version of the ActivityPub plugin.
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
// Register main action that load the Event Bridge For ActivityPub.
\add_action( 'plugins_loaded', array( $this, 'setup_hooks' ) );
@ -101,22 +96,13 @@ class Setup {
return self::$instance;
}
/**
* Getter function for whether the ActivityPub plugin is active.
*
* @return bool True when the ActivityPub plugin is active.
*/
public function is_activitypub_plugin_active(): bool {
return $this->activitypub_plugin_is_active;
}
/**
* Get the current version of the ActivityPub plugin.
*
* @return string The semantic Version.
*/
private static function get_activitypub_plugin_version(): string {
if ( defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) {
if ( \defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) {
return constant( 'ACTIVITYPUB_PLUGIN_VERSION' );
}
return '0.0.0';
@ -178,6 +164,7 @@ class Setup {
\Event_Bridge_For_ActivityPub\Integrations\Event_Organiser::class,
\Event_Bridge_For_ActivityPub\Integrations\EventPrime::class,
\Event_Bridge_For_ActivityPub\Integrations\EventOn::class,
\Event_Bridge_For_ActivityPub\Integrations\Spiffy_Calendar::class,
);
/**
@ -186,9 +173,6 @@ class Setup {
* @return void
*/
public function redetect_active_event_plugins(): void {
if ( ! $this->activitypub_plugin_is_active ) {
return;
}
\delete_transient( 'event_bridge_for_activitypub_active_event_plugins' );
$this->detect_active_event_plugins();
@ -200,11 +184,6 @@ class Setup {
* @return array List of supported event plugins as keys from the SUPPORTED_EVENT_PLUGINS const.
*/
public function detect_active_event_plugins(): array {
// Detection will fail in case the ActivityPub plugin is not active.
if ( ! $this->activitypub_plugin_is_active ) {
return array();
}
$active_event_plugins = \get_transient( 'event_bridge_for_activitypub_active_event_plugins' );
if ( $active_event_plugins ) {
@ -213,7 +192,6 @@ class Setup {
}
if ( ! function_exists( 'get_plugins' ) ) {
// @phpstan-ignore-next-line
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
@ -289,7 +267,7 @@ class Setup {
);
// If we don't have any active event plugins, or the ActivityPub plugin is not enabled, abort here.
if ( empty( $this->active_event_plugins ) || ! $this->activitypub_plugin_is_active ) {
if ( empty( $this->active_event_plugins ) ) {
self::shut_down();
return;
}
@ -312,9 +290,6 @@ class Setup {
// Register the event reminders.
\add_action( 'init', array( Reminder::class, 'init' ) );
// Initialize the handling of "Join" activities.
Join_Handler::init();
// If the Event-Sources feature is enabled and all requirements are met, initialize it.
if ( ! is_user_type_disabled( 'blog' ) && \get_option( 'event_bridge_for_activitypub_event_sources_active' ) ) {
Event_Sources::init();
@ -340,7 +315,7 @@ class Setup {
* @return void
*/
private function register_plugin_specific_hooks(): void {
if ( array_key_exists( \Event_Bridge_For_ActivityPub\Integrations\EventPrime::get_relative_plugin_file(), $this->active_event_plugins ) ) {
if ( \array_key_exists( \Event_Bridge_For_ActivityPub\Integrations\EventPrime::get_relative_plugin_file(), $this->active_event_plugins ) ) {
\Event_Bridge_For_ActivityPub\Integrations\EventPrime::init();
}
}
@ -403,12 +378,6 @@ class Setup {
foreach ( $this->active_event_plugins as $event_plugin ) {
new Event_Plugin_Admin_Notices( $event_plugin );
}
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
if ( ! $this->activitypub_plugin_is_active ) {
// The ActivityPub plugin is not active.
\add_action( 'admin_notices', array( General_Admin_Notices::class, 'activitypub_plugin_not_enabled' ), 10, 0 );
return;
}
if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION, '>=' ) ) {
// The ActivityPub plugin is too old.
\add_action( 'admin_notices', array( General_Admin_Notices::class, 'activitypub_plugin_version_too_old' ), 10, 0 );
@ -429,7 +398,7 @@ class Setup {
*
* @return \Activitypub\Transformer\Base|null|\WP_Error
*/
public function register_activitypub_transformer( $transformer, $data, $object_class ) {
public function register_activitypub_transformer( $transformer, mixed $data, string $object_class ) {
// If the current WordPress object is not a post (e.g., a WP_Comment), don't change the transformer.
if ( 'WP_Post' === $object_class ) {
// Get the transformer for a specific event plugins event or location post type.
@ -506,7 +475,7 @@ class Setup {
// If someone installs this plugin, we simply enable ActivityPub support for all currently active event post types.
$activitypub_supported_post_types = get_option( 'activitypub_support_post_types', array() );
foreach ( $this->active_event_plugins as $event_plugin ) {
if ( ! in_array( $event_plugin->get_post_type(), $activitypub_supported_post_types, true ) ) {
if ( ! \in_array( $event_plugin->get_post_type(), $activitypub_supported_post_types, true ) ) {
$activitypub_supported_post_types[] = $event_plugin->get_post_type();
add_post_type_support( $event_plugin->get_post_type(), 'activitypub' );
}
@ -525,17 +494,6 @@ class Setup {
*/
public function activate(): void {
$this->redetect_active_event_plugins();
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
if ( ! $this->activitypub_plugin_is_active ) {
\deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) );
$notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled();
\wp_die(
// @phpstan-ignore-next-line
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
'Plugin dependency check',
array( 'back_link' => true ),
);
}
if ( empty( $this->active_event_plugins ) ) {
\deactivate_plugins( plugin_basename( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE ) );
@ -552,7 +510,7 @@ class Setup {
}
/**
* Maybe (depending on active event plugins) make it possible to querly event terms by `?term_id=<term_id>`.
* Maybe (depending on active event plugins) make it possible to query event terms by `?term_id=<term_id>`.
*
* @return void
*/
@ -579,7 +537,7 @@ class Setup {
*
* @return array The query variables.
*/
public static function add_term_query_var( $vars ) {
public static function add_term_query_var( array $vars ): array {
$vars[] = 'term_id';
return $vars;
@ -588,9 +546,9 @@ class Setup {
/**
* Filters the queried object.
*
* @param \WP_Term|\WP_Post_Type|\WP_Post|\WP_User|\WP_Comment|null $queried_object The queried object.
* @param WP_Term|WP_Post_Type|WP_Post|WP_User|WP_Comment|null $queried_object The queried object.
*/
public function maybe_detect_event_plugins_location_term( $queried_object ) {
public function maybe_detect_event_plugins_location_term( mixed $queried_object ) {
if ( $queried_object ) {
return $queried_object;
}
@ -601,7 +559,7 @@ class Setup {
$queried_object = \get_term( $term_id );
}
if ( $queried_object instanceof \WP_Term && $this->is_place_taxonomy_of_active_event_plugin( $queried_object->taxonomy ) ) {
if ( $queried_object instanceof WP_Term && $this->is_place_taxonomy_of_active_event_plugin( $queried_object->taxonomy ) ) {
return $queried_object;
}
@ -614,7 +572,7 @@ class Setup {
* @param string $taxonomy The taxonomy.
* @return boolean
*/
private function is_place_taxonomy_of_active_event_plugin( $taxonomy ): bool {
private function is_place_taxonomy_of_active_event_plugin( string $taxonomy ): bool {
foreach ( $this->active_event_plugins as $event_plugin ) {
if ( $event_plugin::get_place_taxonomy() === $taxonomy ) {
return true;
@ -684,7 +642,7 @@ class Setup {
$event_plugin_integrations = $setup->get_active_event_plugins();
foreach ( $event_plugin_integrations as $event_plugin_integration ) {
if ( $event_plugin_integration instanceof Feature_Event_Sources ) {
return get_class( $event_plugin_integration );
return \get_class( $event_plugin_integration );
}
}
return '';