Catch more cases for errors in admin UI when ActivityPub plugin is not active
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 48s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m6s
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 48s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m6s
This commit is contained in:
parent
a1c776641f
commit
355dfb8991
4 changed files with 79 additions and 45 deletions
|
@ -92,6 +92,15 @@ class Setup {
|
||||||
return self::$instance;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LooksUp the current version of the ActivityPub.
|
* LooksUp the current version of the ActivityPub.
|
||||||
*
|
*
|
||||||
|
@ -135,6 +144,9 @@ class Setup {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function redetect_active_event_plugins(): void {
|
public function redetect_active_event_plugins(): void {
|
||||||
|
if ( ! $this->activitypub_plugin_is_active ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
delete_transient( 'event_bridge_for_activitypub_active_event_plugins' );
|
delete_transient( 'event_bridge_for_activitypub_active_event_plugins' );
|
||||||
$this->detect_active_event_plugins();
|
$this->detect_active_event_plugins();
|
||||||
}
|
}
|
||||||
|
@ -152,6 +164,11 @@ class Setup {
|
||||||
return $active_event_plugins;
|
return $active_event_plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detection will fail in case the ActivityPub plugin is not active.
|
||||||
|
if ( ! $this->activitypub_plugin_is_active ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'get_plugins' ) ) {
|
if ( ! function_exists( 'get_plugins' ) ) {
|
||||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||||
}
|
}
|
||||||
|
@ -203,16 +220,6 @@ class Setup {
|
||||||
$this->activitypub_plugin_is_active = defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) || \is_plugin_active( 'activitypub/activitypub.php' );
|
$this->activitypub_plugin_is_active = defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) || \is_plugin_active( 'activitypub/activitypub.php' );
|
||||||
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
|
$this->activitypub_plugin_version = self::get_activitypub_plugin_version();
|
||||||
|
|
||||||
// Detect active supported event plugins.
|
|
||||||
$this->detect_active_event_plugins();
|
|
||||||
|
|
||||||
// Register hook that runs when this plugin gets activated.
|
|
||||||
register_activation_hook( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE, array( $this, 'activate' ) );
|
|
||||||
|
|
||||||
// Register listeners whenever any plugin gets activated or deactivated.
|
|
||||||
add_action( 'activated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
|
||||||
add_action( 'deactivated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
|
||||||
|
|
||||||
// Add hook that takes care of all notices in the Admin UI.
|
// Add hook that takes care of all notices in the Admin UI.
|
||||||
add_action( 'admin_init', array( $this, 'do_admin_notices' ) );
|
add_action( 'admin_init', array( $this, 'do_admin_notices' ) );
|
||||||
|
|
||||||
|
@ -222,6 +229,13 @@ class Setup {
|
||||||
// Add hook that loads CSS and JavaScript files for the Admin UI.
|
// Add hook that loads CSS and JavaScript files for the Admin UI.
|
||||||
add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) );
|
add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) );
|
||||||
|
|
||||||
|
// Register hook that runs when this plugin gets activated.
|
||||||
|
register_activation_hook( EVENT_BRIDGE_FOR_ACTIVITYPUB_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||||
|
|
||||||
|
// Register listeners whenever any plugin gets activated or deactivated.
|
||||||
|
add_action( 'activated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
||||||
|
add_action( 'deactivated_plugin', array( $this, 'redetect_active_event_plugins' ) );
|
||||||
|
|
||||||
// Register the settings page(s) of this plugin to the WordPress admin menu.
|
// Register the settings page(s) of this plugin to the WordPress admin menu.
|
||||||
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
|
add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) );
|
||||||
add_filter(
|
add_filter(
|
||||||
|
@ -230,7 +244,15 @@ class Setup {
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we don't have any active event plugins, or the ActivityPub plugin is not enabled, abort here.
|
// 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 ( ! $this->activitypub_plugin_is_active ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect active supported event plugins.
|
||||||
|
$this->detect_active_event_plugins();
|
||||||
|
|
||||||
|
// If we don't have any active event plugins, or the ActivityPub plugin is not enabled, abort here.
|
||||||
|
if ( empty( $this->active_event_plugins ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,15 +314,17 @@ class Setup {
|
||||||
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
|
// Check if any general admin notices are needed and add actions to insert the needed admin notices.
|
||||||
if ( ! $this->activitypub_plugin_is_active ) {
|
if ( ! $this->activitypub_plugin_is_active ) {
|
||||||
// The ActivityPub plugin is not active.
|
// The ActivityPub plugin is not active.
|
||||||
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
|
add_action( 'admin_notices', array( General_Admin_Notices::class, 'activitypub_plugin_not_enabled' ), 10, 1 );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
if ( ! version_compare( $this->activitypub_plugin_version, EVENT_BRIDGE_FOR_ACTIVITYPUB_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
||||||
// The ActivityPub plugin is too old.
|
// The ActivityPub plugin is too old.
|
||||||
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 );
|
add_action( 'admin_notices', array( General_Admin_Notices::class, 'activitypub_plugin_version_too_old' ), 10, 1 );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if ( empty( $this->active_event_plugins ) ) {
|
if ( empty( $this->active_event_plugins ) ) {
|
||||||
// No supported Event Plugin is active.
|
// No supported Event Plugin is active.
|
||||||
add_action( 'admin_notices', array( 'Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
|
add_action( 'admin_notices', array( General_Admin_Notices::class, 'no_supported_event_plugin_active' ), 10, 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap event_bridge_for_activitypub-admin-table-container">
|
<div class="wrap event_bridge_for_activitypub-admin-table-container">
|
||||||
|
<?php if ( defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) { ?>
|
||||||
<!-- Table title with add new button like on post edit pages -->
|
<!-- Table title with add new button like on post edit pages -->
|
||||||
<div class="event_bridge_for_activitypub-admin-table-top">
|
<div class="event_bridge_for_activitypub-admin-table-top">
|
||||||
<h2 class="wp-heading-inline"> <?php esc_html_e( 'List of Event Sources', 'event-bridge-for-activitypub' ); ?> </h2>
|
<h2 class="wp-heading-inline"> <?php esc_html_e( 'List of Event Sources', 'event-bridge-for-activitypub' ); ?> </h2>
|
||||||
|
@ -51,5 +52,6 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
);
|
);
|
||||||
|
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
use Activitypub\Activity\Extended_Object\Event;
|
||||||
|
use Event_Bridge_For_ActivityPub\Setup;
|
||||||
|
|
||||||
|
$activitypub_plugin_is_active = Setup::get_instance()->is_activitypub_plugin_active();
|
||||||
|
|
||||||
if ( ! isset( $args ) || ! array_key_exists( 'event_terms', $args ) ) {
|
if ( ! isset( $args ) || ! array_key_exists( 'event_terms', $args ) ) {
|
||||||
return;
|
return;
|
||||||
|
@ -100,6 +103,7 @@ $current_category_mapping = \get_option( 'event_bridge_for_activitypub_ev
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if ( $activitypub_plugin_is_active ) { ?>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2><?php \esc_html_e( 'Event Sources', 'event-bridge-for-activitypub' ); ?></h2>
|
<h2><?php \esc_html_e( 'Event Sources', 'event-bridge-for-activitypub' ); ?></h2>
|
||||||
<?php
|
<?php
|
||||||
|
@ -215,6 +219,7 @@ $current_category_mapping = \get_option( 'event_bridge_for_activitypub_ev
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2> <?php esc_html_e( 'ActivityPub Event Category', 'event-bridge-for-activitypub' ); ?> </h2>
|
<h2> <?php esc_html_e( 'ActivityPub Event Category', 'event-bridge-for-activitypub' ); ?> </h2>
|
||||||
|
|
|
@ -24,6 +24,7 @@ use Event_Bridge_For_ActivityPub\Admin\Health_Check;
|
||||||
);
|
);
|
||||||
|
|
||||||
$active_event_plugins = Setup::get_instance()->get_active_event_plugins();
|
$active_event_plugins = Setup::get_instance()->get_active_event_plugins();
|
||||||
|
$activitypub_plugin_is_active = Setup::get_instance()->is_activitypub_plugin_active();
|
||||||
$event_bridge_for_activitypub_status_ok = true;
|
$event_bridge_for_activitypub_status_ok = true;
|
||||||
$example_event_post = Health_Check::get_most_recent_event_posts();
|
$example_event_post = Health_Check::get_most_recent_event_posts();
|
||||||
|
|
||||||
|
@ -45,7 +46,9 @@ WP_Filesystem();
|
||||||
<h2><?php \esc_html_e( 'Status', 'event-bridge-for-activitypub' ); ?></h2>
|
<h2><?php \esc_html_e( 'Status', 'event-bridge-for-activitypub' ); ?></h2>
|
||||||
<p><?php \esc_html_e( 'The Event Bridge for ActivityPub detected the following (activated) event plugins:', 'event-bridge-for-activitypub' ); ?></p>
|
<p><?php \esc_html_e( 'The Event Bridge for ActivityPub detected the following (activated) event plugins:', 'event-bridge-for-activitypub' ); ?></p>
|
||||||
<?php
|
<?php
|
||||||
if ( empty( $active_event_plugins ) ) {
|
if ( ! $activitypub_plugin_is_active ) {
|
||||||
|
$notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled();
|
||||||
|
} elseif ( empty( $active_event_plugins ) ) {
|
||||||
$notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active();
|
$notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active();
|
||||||
}
|
}
|
||||||
echo '<p>⚠' . \wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ) . '</p>';
|
echo '<p>⚠' . \wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ) . '</p>';
|
||||||
|
|
Loading…
Reference in a new issue