improve admin notices
This commit is contained in:
parent
8aa90b1005
commit
9af8b4b397
2 changed files with 79 additions and 52 deletions
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* Class responsible for Event Plugin related admin notices.
|
||||
* Class responsible for general admin notices.
|
||||
*
|
||||
* Notices for guiding to proper configuration of ActivityPub with event plugins.
|
||||
* Notices for guiding to proper configuration of this plugin.
|
||||
*
|
||||
* @package Activitypub_Event_Extensions
|
||||
* @since 1.0.0
|
||||
|
@ -11,56 +11,28 @@
|
|||
namespace Activitypub_Event_Extensions\Admin;
|
||||
|
||||
/**
|
||||
* Class responsible for Event Plugin related admin notices.
|
||||
* Class responsible for general admin notices.
|
||||
*
|
||||
* Notices for guiding to proper configuration of ActivityPub with event plugins.
|
||||
* Notices for guiding to proper configuration of this plugin.
|
||||
* - ActivityPub plugin not installed and activated
|
||||
* - No supported Event Plugin installed and activated
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class General_Admin_Notices {
|
||||
/**
|
||||
* Warning if the plugin is Active and the ActivityPub plugin is not.
|
||||
* URL of the ActivityPub plugin. Needed when the ActivityPub plugin is not installed.
|
||||
*/
|
||||
public static function do_admin_notice_activitypub_plugin_not_enabled() {
|
||||
$activitypub_plugin_url = 'https://wordpress.org/plugins/activitypub/';
|
||||
const ACTIVITYPUB_PLUGIN_URL = 'https://wordpress.org/plugins/activitypub';
|
||||
|
||||
$notice = sprintf(
|
||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||
_x(
|
||||
'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( $activitypub_plugin_url ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
);
|
||||
$allowed_html = array(
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'title' => true,
|
||||
),
|
||||
);
|
||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, $allowed_html ) . '</p></div>';
|
||||
}
|
||||
const ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL = 'https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-extensions#events-plugin-that-will-be-supported-at-first';
|
||||
|
||||
/**
|
||||
* Warning that no supported event plugin can be found.
|
||||
* Allowed HTML for admin notices.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static function do_admin_notice_no_supported_event_plugin_active() {
|
||||
$supported_event_plugins_url = 'https://code.event-federation.eu/Event-Federation/wordpress-activitypub-event-extensions#events-plugin-that-will-be-supported-at-first';
|
||||
|
||||
$notice = sprintf(
|
||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||
_x(
|
||||
'The Plugin <i>ActivityPub Event Extensions</i> is of no use, because you do not have installed and activated a supported Event Plugin.
|
||||
<br> For a list of supported Event Plugins see <a href="%1$s">here</a>.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( $supported_event_plugins_url ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
);
|
||||
$allowed_html = array(
|
||||
const ALLOWED_HTML = array(
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'title' => true,
|
||||
|
@ -68,6 +40,61 @@ class General_Admin_Notices {
|
|||
'br',
|
||||
'i',
|
||||
);
|
||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, $allowed_html ) . '</p></div>';
|
||||
|
||||
/**
|
||||
* Admin notice when the ActivityPub plugin is not enabled.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_admin_notice_activitypub_plugin_not_enabled(): string {
|
||||
return sprintf(
|
||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||
_x(
|
||||
'For the ActivityPub Event Extensions to work, you will need to install and activate the <a href="%1$s">ActivityPub</a> plugin.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( self::ACTIVITYPUB_PLUGIN_URL ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning that no supported event plugin can be found.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_admin_notice_no_supported_event_plugin_active(): string {
|
||||
return sprintf(
|
||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||
_x(
|
||||
'The Plugin <i>ActivityPub Event Extensions</i> is of no use, because you do not have installed and activated a supported Event Plugin.
|
||||
<br> For a list of supported Event Plugins see <a href="%1$s">here</a>.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning if the plugin is Active and the ActivityPub plugin is not.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function activitypub_plugin_not_enabled() {
|
||||
$notice = self::get_admin_notice_activitypub_plugin_not_enabled();
|
||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning when no supported Even Plugin is installed and active.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function no_supported_event_plugin_active() {
|
||||
$notice = self::get_admin_notice_no_supported_event_plugin_active();
|
||||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
|
||||
namespace Activitypub_Event_Extensions;
|
||||
|
||||
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
|
||||
use Activitypub_Event_Extensions\Admin\Event_Plugin_Admin_Notices;
|
||||
use Activitypub_Event_Extensions\Admin\General_Admin_Notices;
|
||||
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
@ -144,17 +145,21 @@ class Setup {
|
|||
}
|
||||
|
||||
/**
|
||||
* Fires the initialization of admin notices for all active supported event plugins.s
|
||||
* Fires the initialization of admin notices.
|
||||
*/
|
||||
public function do_admin_notices(): void {
|
||||
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 ) {
|
||||
add_action( 'admin_notices', array( new General_Admin_Notices(), 'do_admin_notice_activitypub_plugin_not_enabled' ), 10, 1 );
|
||||
// The ActivityPub plugin is not active.
|
||||
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
|
||||
}
|
||||
if ( empty( $this->active_event_plugins ) ) {
|
||||
add_action( 'admin_notices', array( new General_Admin_Notices(), 'do_admin_notice_no_supported_event_plugin_active' ), 10, 1 );
|
||||
// No supported Event Plugin is active.
|
||||
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'no_supported_event_plugin_active' ), 10, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,29 +203,24 @@ class Setup {
|
|||
// Don't allow plugin activation, when the ActivityPub plugin is not activated yet.
|
||||
if ( ! $this->activitypub_plugin_is_active ) {
|
||||
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
|
||||
$notice = sprintf(
|
||||
/* translators: 1: the name of the event plugin a admin notice is shown. 2: The name of the ActivityPub plugin. */
|
||||
_x(
|
||||
'To use this plugin install and activate the <a href="%1$s">%2$s</a> plugin first.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( 'https://wordpress.org/plugins/activitypub' ),
|
||||
esc_html( 'ActivityPub' )
|
||||
);
|
||||
$allowed_html = array(
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'title' => true,
|
||||
),
|
||||
);
|
||||
$notice = General_Admin_Notices::get_admin_notice_activitypub_plugin_not_enabled();
|
||||
wp_die(
|
||||
wp_kses( $notice, $allowed_html ),
|
||||
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
|
||||
'Plugin dependency check',
|
||||
array( 'back_link' => true ),
|
||||
);
|
||||
}
|
||||
// If someone installs this plugin, we simply enable ActivityPub support for the event post type, without asking.
|
||||
|
||||
if ( empty( $this->active_event_plugins ) ) {
|
||||
deactivate_plugins( plugin_basename( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE ) );
|
||||
$notice = General_Admin_Notices::get_admin_notice_no_supported_event_plugin_active();
|
||||
wp_die(
|
||||
wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ),
|
||||
'Plugin dependency check',
|
||||
array( 'back_link' => true ),
|
||||
);
|
||||
}
|
||||
// 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['post_type'], $activitypub_supported_post_types, true ) ) {
|
||||
|
|
Loading…
Reference in a new issue