add checks for minimum version of the activitypub plugin
This commit is contained in:
parent
0b3974b255
commit
4e2c1fb23a
3 changed files with 56 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
|||
* License URI: https://www.gnu.org/licenses/agpl-3.0.de.html
|
||||
* Requires PHP: 8.1
|
||||
*
|
||||
* ActivityPub plugin tested up to: 3.2.2
|
||||
* Requires at least ActivityPub plugin with version >= 3.2.2. ActivityPub plugin tested up to: 3.2.2.
|
||||
*
|
||||
* @package activitypub-event-extensions
|
||||
* @license AGPL-3.0-or-later
|
||||
|
@ -26,6 +26,7 @@ define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE', plugin_dir_path( __FILE__ )
|
|||
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_VERSION', current( get_file_data( __FILE__, array( 'Version' ), 'plugin' ) ) );
|
||||
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_DOMAIN', 'activitypub-event-extensions' );
|
||||
define( 'ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION', '3.2.2' );
|
||||
|
||||
// Include and register the autoloader class for automatic loading of plugin classes.
|
||||
require_once ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_DIR . '/includes/class-autoloader.php';
|
||||
|
|
|
@ -49,14 +49,31 @@ class General_Admin_Notices {
|
|||
*/
|
||||
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. */
|
||||
/* translators: 1: An URL that points to 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 notice when the ActivityPub plugin version is too old.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_admin_notice_activitypub_plugin_version_too_old(): string {
|
||||
return sprintf(
|
||||
/* translators: 1: The name of the ActivityPub plugin. 2: The minimum required version number of the ActivityPub plugin. */
|
||||
_x(
|
||||
'Please upgrade your <a href="%1$s">ActivityPub</a> plugin. At least version %2$s is required for the ActivityPub event extensions to work.',
|
||||
'admin notice',
|
||||
'activitypub-event-extensions'
|
||||
),
|
||||
esc_html( self::ACTIVITYPUB_PLUGIN_URL ),
|
||||
admin_url( 'options-general.php?page=activitypub&tab=settings' )
|
||||
esc_html( ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -67,15 +84,14 @@ class General_Admin_Notices {
|
|||
*/
|
||||
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. */
|
||||
/* translators: 1: An URL to the list of supported event plugins. */
|
||||
_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' )
|
||||
esc_html( self::ACTIVITYPUB_EVENT_EXTENSIONS_SUPPORTED_EVENT_PLUGINS_URL )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,6 +105,16 @@ class General_Admin_Notices {
|
|||
echo '<div class="notice notice-warning"><p>' . \wp_kses( $notice, self::ALLOWED_HTML ) . '</p></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning if the plugin is Active and the ActivityPub plugins version is too old.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function activitypub_plugin_version_too_old(): void {
|
||||
$notice = self::get_admin_notice_activitypub_plugin_version_too_old();
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -37,6 +37,13 @@ class Setup {
|
|||
*/
|
||||
protected $activitypub_plugin_is_active = false;
|
||||
|
||||
/**
|
||||
* Keep the current version of the current ActivityPub plugin.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $activitypub_plugin_version = '';
|
||||
|
||||
/**
|
||||
* Holds an array of the currently activated supported event plugins.
|
||||
*
|
||||
|
@ -53,7 +60,13 @@ class Setup {
|
|||
*/
|
||||
protected function __construct() {
|
||||
$this->activitypub_plugin_is_active = is_plugin_active( 'activitypub/activitypub.php' );
|
||||
// TODO: decide whether we want to do anything at all when ActivityPub plugin is note active.
|
||||
// if ( ! $this->activitypub_plugin_is_active ) {
|
||||
// deactivate_plugins( ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_FILE );
|
||||
// return;
|
||||
// }.
|
||||
$this->active_event_plugins = self::detect_active_event_plugins();
|
||||
$this->activitypub_plugin_version = get_file_data( WP_PLUGIN_DIR . '/activitypub/activitypub.php', array( 'Version' ) )[0];
|
||||
$this->setup_hooks();
|
||||
}
|
||||
|
||||
|
@ -151,6 +164,12 @@ class Setup {
|
|||
'plugin_action_links_' . ACTIVITYPUB_EVENT_EXTENSIONS_PLUGIN_BASENAME,
|
||||
array( Settings_Page::class, 'settings_link' )
|
||||
);
|
||||
|
||||
// Check if the minimum required version of the ActivityPub plugin is installed.
|
||||
if ( version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
|
||||
}
|
||||
|
||||
|
@ -183,11 +202,14 @@ class Setup {
|
|||
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( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_not_enabled' ), 10, 1 );
|
||||
}
|
||||
if ( version_compare( $this->activitypub_plugin_version, ACTIVITYPUB_EVENT_EXTENSIONS_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) {
|
||||
// The ActivityPub plugin is too old.
|
||||
add_action( 'admin_notices', array( 'Activitypub_Event_Extensions\Admin\General_Admin_Notices', 'activitypub_plugin_version_too_old' ), 10, 1 );
|
||||
}
|
||||
if ( empty( $this->active_event_plugins ) ) {
|
||||
// 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 );
|
||||
|
|
Loading…
Reference in a new issue