From dee2bf6b3ea475232353d7ba50622b1e2f6ff08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Fri, 18 Oct 2024 15:52:36 +0200 Subject: [PATCH 1/6] wip on status and health check pages --- includes/admin/class-health-check.php | 127 +++++++++++++++++++++++++ includes/admin/class-settings-page.php | 46 ++++++--- includes/class-settings.php | 10 ++ includes/class-setup.php | 3 +- templates/status.php | 15 +++ 5 files changed, 187 insertions(+), 14 deletions(-) create mode 100644 includes/admin/class-health-check.php create mode 100644 templates/status.php diff --git a/includes/admin/class-health-check.php b/includes/admin/class-health-check.php new file mode 100644 index 0000000..efcc6c0 --- /dev/null +++ b/includes/admin/class-health-check.php @@ -0,0 +1,127 @@ + __( 'ActivityPub Event Transformer Test', 'activitypub-event-bridge' ), + 'test' => array( self::class, 'test_event_transformation' ), + ); + + return $tests; + } + + /** + * The the transformation of the most recent event posts. + * + * @return array + */ + public static function test_event_transformation() { + $result = array( + 'label' => \__( 'Transformation of Events to a valid ActivityStreams representation.', 'activitypub' ), + 'status' => 'good', + 'badge' => array( + 'label' => \__( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ), + 'color' => 'green', + ), + 'description' => \sprintf( + '

%s

', + \__( 'The transformation of your most recent events was successful.', 'activitypub-event-bridge' ) + ), + 'actions' => '', + 'test' => 'test_event_transformation', + ); + + $check = self::transform_most_recent_event_posts(); + + if ( true === $check ) { + return $result; + } + + $result['status'] = 'critical'; + $result['label'] = \__( 'One or more of your most recent events failed to transform to ActivityPub', 'activitypub-event-bridge' ); + $result['badge']['color'] = 'red'; + $result['description'] = \sprintf( + '

%s

', + $check->get_error_message() + ); + + return $result; + } + + /** + * Transform the most recent event posts. + */ + public static function transform_most_recent_event_posts() { + return true; + } + + /** + * Retrieves information like name and version from active event plugins. + */ + private static function get_info_about_active_event_plugins() { + $active_event_plugins = Setup::get_instance()->get_active_event_plugins(); + $info = array(); + foreach ( $active_event_plugins as $active_event_plugin ) { + $event_plugin_file = $active_event_plugin->get_plugin_file(); + $event_plugin_data = \get_plugin_data( $event_plugin_file ); + $event_plugin_name = isset( $event_plugin_data['Plugin Name'] ) ? $event_plugin_data['Plugin Name'] : 'Name not found'; + $event_plugin_version = isset( $event_plugin_version['Plugin Version'] ) ? $event_plugin_version['Plugin Version'] : 'Version not found'; + + $info[] = array( + 'event_plugin_name' => $event_plugin_name, + 'event_plugin_version' => $event_plugin_version, + 'event_plugin_file' => $event_plugin_file, + ); + } + } + + /** + * Static function for generating site debug data when required. + * + * @param array $info The debug information to be added to the core information page. + * @return array The extended information. + */ + public static function add_debug_information( $info ) { + $info['activitypub_event_bridge'] = array( + 'label' => __( 'ActivityPub Event Bridge', 'activitypub-event-bridge' ), + 'fields' => array( + 'plugin_version' => array( + 'label' => __( 'Plugin Version', 'activitypub' ), + 'value' => ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_VERSION, + 'private' => true, + ), + 'active_event_plugins' => self::get_info_about_active_event_plugins(), + ), + ); + + return $info; + } +} diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php index 08a36d6..645495a 100644 --- a/includes/admin/class-settings-page.php +++ b/includes/admin/class-settings-page.php @@ -89,21 +89,41 @@ class Settings_Page { * @return void */ public static function settings_page(): void { - $plugin_setup = Setup::get_instance(); - - $event_plugins = $plugin_setup->get_active_event_plugins(); - - $event_terms = array(); - - foreach ( $event_plugins as $event_plugin ) { - $event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) ); + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( empty( $_GET['tab'] ) ) { + $tab = 'status'; + } else { + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $tab = sanitize_key( $_GET['tab'] ); } - $args = array( - 'slug' => self::SETTINGS_SLUG, - 'event_terms' => $event_terms, - ); + switch ( $tab ) { + case 'settings': + $plugin_setup = Setup::get_instance(); - \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args ); + $event_plugins = $plugin_setup->get_active_event_plugins(); + + $event_terms = array(); + + foreach ( $event_plugins as $event_plugin ) { + $event_terms = array_merge( $event_terms, self::get_event_terms( $event_plugin ) ); + } + + $args = array( + 'slug' => self::SETTINGS_SLUG, + 'event_terms' => $event_terms, + ); + + \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args ); + break; + case 'status': + default: + wp_enqueue_script( 'plugin-install' ); + add_thickbox(); + wp_enqueue_script( 'updates' ); + + \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/status.php', true ); + break; + } } } diff --git a/includes/class-settings.php b/includes/class-settings.php index 922531f..69ae58f 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -61,6 +61,16 @@ class Settings { 'sanitize_callback' => array( self::class, 'sanitize_event_category_mappings' ), ) ); + + \register_setting( + 'activitypub-event-bridge', + 'activitypub_event_bridge_initially_activated', + array( + 'type' => 'boolean', + 'description' => \__( 'Whether the plugin just got activated for the first time.', 'activitypub' ), + 'default' => true, + ) + ); } /** diff --git a/includes/class-setup.php b/includes/class-setup.php index a03c988..057ff3c 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -17,6 +17,7 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use ActivityPub_Event_Bridge\Admin\Event_Plugin_Admin_Notices; use ActivityPub_Event_Bridge\Admin\General_Admin_Notices; +use ActivityPub_Event_Bridge\Admin\Health_Check; use ActivityPub_Event_Bridge\Admin\Settings_Page; use ActivityPub_Event_Bridge\Plugins\Event_Plugin; @@ -173,8 +174,8 @@ class Setup { return; } + add_action( 'init', array( Health_Check::class, 'init' ) ); add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) ); - add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) ); add_filter( diff --git a/templates/status.php b/templates/status.php new file mode 100644 index 0000000..75bb595 --- /dev/null +++ b/templates/status.php @@ -0,0 +1,15 @@ + + +
+
+

+

This is so cool!

+
+
-- 2.39.5 From 127df329b6c6a8f632d30aba9128cab92d62edbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 19 Oct 2024 13:06:01 +0200 Subject: [PATCH 2/6] improved settings page layout --- assets/css/activitypub-event-bridge-admin.css | 52 +++++++++++++++++++ .../activitypub-event-extensions-admin.css | 6 --- includes/plugins/class-event-plugin.php | 12 +++++ templates/admin-header.php | 33 ++++++++++++ templates/settings.php | 27 +++++----- templates/status.php | 23 ++++++-- 6 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 assets/css/activitypub-event-bridge-admin.css delete mode 100644 assets/css/activitypub-event-extensions-admin.css create mode 100644 templates/admin-header.php diff --git a/assets/css/activitypub-event-bridge-admin.css b/assets/css/activitypub-event-bridge-admin.css new file mode 100644 index 0000000..a3575c3 --- /dev/null +++ b/assets/css/activitypub-event-bridge-admin.css @@ -0,0 +1,52 @@ +.activitypub-event-bridge-settings-page .box { + border: 1px solid #c3c4c7; + background-color: #fff; + padding: 1em 1.5em; + margin-bottom: 1.5em; +} + +.activitypub-event-bridge-settings { + max-width: 800px; + margin: 0 auto; +} + +.activitypub-event-bridge-settings-header { + text-align: center; + margin: 0 0 1rem; + background: #fff; + border-bottom: 1px solid #dcdcde; +} + +.activitypub-event-bridge-settings-title-section { + display: flex; + align-items: center; + justify-content: center; + clear: both; + padding-top: 8px; +} + +.activitypub-event-bridge-settings-tabs-wrapper { + display: -ms-inline-grid; + -ms-grid-columns: auto auto auto auto; + vertical-align: top; + display: inline-grid; + grid-template-columns: auto auto auto auto; +} + +.activitypub-event-bridge-settings-tab.active { + box-shadow: inset 0 -3px #3582c4; + font-weight: 600; +} + +.activitypub-event-bridge-settings-tab { + display: block; + text-decoration: none; + color: inherit; + padding: .5rem 1rem 1rem; + margin: 0 1rem; + transition: box-shadow .5s ease-in-out; +} + +.activitypub-event-bridge-settings .box h3 { + font-size: 1.1rem!important; +} \ No newline at end of file diff --git a/assets/css/activitypub-event-extensions-admin.css b/assets/css/activitypub-event-extensions-admin.css deleted file mode 100644 index c59d1a1..0000000 --- a/assets/css/activitypub-event-extensions-admin.css +++ /dev/null @@ -1,6 +0,0 @@ -.activitypub-event-bridge-settings-page .box { - border: 1px solid #c3c4c7; - background-color: #fff; - padding: 1em 1.5em; - margin-bottom: 1.5em; -} diff --git a/includes/plugins/class-event-plugin.php b/includes/plugins/class-event-plugin.php index f70cfa0..7374794 100644 --- a/includes/plugins/class-event-plugin.php +++ b/includes/plugins/class-event-plugin.php @@ -53,6 +53,18 @@ abstract class Event_Plugin { return ''; } + /** + * Get the plugins name from the main plugin-file's top-level-file-comment. + */ + final public static function get_plugin_name(): string { + $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . static::get_plugin_file() ); + if ( isset( $plugin_data['Name'] ) ) { + return $plugin_data['Name']; + } else { + return ''; + } + } + /** * Detects whether the current screen is a admin page of the event plugin. */ diff --git a/templates/admin-header.php b/templates/admin-header.php new file mode 100644 index 0000000..1890558 --- /dev/null +++ b/templates/admin-header.php @@ -0,0 +1,33 @@ + '', + 'settings' => '', + ) +); +?> + +
+
+

+
+ + +
+
diff --git a/templates/settings.php b/templates/settings.php index 8eb382e..58f1bed 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -13,6 +13,14 @@ // Exit if accessed directly. defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore +\load_template( + __DIR__ . '/admin-header.php', + true, + array( + 'settings' => 'active', + ) +); + use Activitypub\Activity\Extended_Object\Event; if ( ! isset( $args ) || ! array_key_exists( 'event_terms', $args ) ) { @@ -31,19 +39,12 @@ $selected_default_event_category = \get_option( 'activitypub_event_bridge_defaul $current_category_mapping = \get_option( 'activitypub_event_bridge_event_category_mappings', array() ); ?> -
-
-

-
-
-
- -
+
-

+

@@ -59,11 +60,9 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
-
- -
-

+ +

@@ -96,8 +95,8 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
+
-
diff --git a/templates/status.php b/templates/status.php index 75bb595..36d8b74 100644 --- a/templates/status.php +++ b/templates/status.php @@ -5,11 +5,28 @@ * @package ActivityPub_Event_Bridge */ +// Exit if accessed directly. +defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore + +use ActivityPub_Event_Bridge\Setup; + +\load_template( + __DIR__ . '/admin-header.php', + true, + array( + 'status' => 'active', + ) +); + +$active_event_plugins = Setup::get_instance()->get_active_event_plugins(); + ?> -
+
-

-

This is so cool!

+

+ +

get_plugin_name() ); ?>

+
-- 2.39.5 From fdfdf6c0b2c56a8f0dba1597c7a207e04ce29d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 19 Oct 2024 13:26:10 +0200 Subject: [PATCH 3/6] improve warning notices when event post type is not enabled for activitypub --- includes/class-setup.php | 13 ++++++------- includes/plugins/class-event-plugin.php | 10 +++++----- includes/plugins/class-eventin.php | 8 ++++---- includes/plugins/class-events-manager.php | 8 ++++---- includes/plugins/class-gatherpress.php | 8 ++++---- .../plugins/class-modern-events-calendar-lite.php | 8 ++++---- includes/plugins/class-the-events-calendar.php | 8 ++++---- includes/plugins/class-vs-event-list.php | 8 ++++---- includes/plugins/class-wp-event-manager.php | 8 ++++---- 9 files changed, 39 insertions(+), 40 deletions(-) diff --git a/includes/class-setup.php b/includes/class-setup.php index 057ff3c..bfaef37 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -168,6 +168,12 @@ class Setup { add_action( 'admin_init', array( $this, 'do_admin_notices' ) ); add_action( 'admin_init', array( Settings::class, 'register_settings' ) ); + add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) ); + add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) ); + add_filter( + 'plugin_action_links_' . ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_BASENAME, + array( Settings_Page::class, 'settings_link' ) + ); // 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 ) { @@ -175,13 +181,6 @@ class Setup { } add_action( 'init', array( Health_Check::class, 'init' ) ); - add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_styles' ) ); - add_action( 'admin_menu', array( Settings_Page::class, 'admin_menu' ) ); - - add_filter( - 'plugin_action_links_' . ACTIVITYPUB_EVENT_BRIDGE_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_BRIDGE_ACTIVITYPUB_PLUGIN_MIN_VERSION ) ) { diff --git a/includes/plugins/class-event-plugin.php b/includes/plugins/class-event-plugin.php index 7374794..f08b5c0 100644 --- a/includes/plugins/class-event-plugin.php +++ b/includes/plugins/class-event-plugin.php @@ -45,12 +45,12 @@ abstract class Event_Plugin { abstract public static function get_event_category_taxonomy(): string; /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The IDs of one or several admin/settings pages. */ - public static function get_settings_page(): string { - return ''; + public static function get_settings_pages(): array { + return array(); } /** @@ -74,7 +74,7 @@ abstract class Event_Plugin { // Check if we are on a edit page for the event, or on the settings page of the event plugin. $is_event_plugins_edit_page = 'edit' === $screen->base && static::get_post_type() === $screen->post_type; - $is_event_plugins_settings_page = static::get_settings_page() === $screen->id; + $is_event_plugins_settings_page = in_array( $screen->id, static::get_settings_pages(), true); return $is_event_plugins_edit_page || $is_event_plugins_settings_page; } diff --git a/includes/plugins/class-eventin.php b/includes/plugins/class-eventin.php index fcab7c8..6584e85 100644 --- a/includes/plugins/class-eventin.php +++ b/includes/plugins/class-eventin.php @@ -41,12 +41,12 @@ final class Eventin extends Event_plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page url. */ - public static function get_settings_page(): string { - return 'eventin'; // Base always is wp-admin/admin.php?page=eventin. + public static function get_settings_pages(): array { + return array( 'eventin' ); // Base always is wp-admin/admin.php?page=eventin. } /** diff --git a/includes/plugins/class-events-manager.php b/includes/plugins/class-events-manager.php index feffcc5..02ca060 100644 --- a/includes/plugins/class-events-manager.php +++ b/includes/plugins/class-events-manager.php @@ -41,12 +41,12 @@ final class Events_Manager extends Event_Plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { - return 'wp-admin/edit.php?post_type=event&page=events-manager-options#general'; + public static function get_settings_page(): array { + return array(); } /** diff --git a/includes/plugins/class-gatherpress.php b/includes/plugins/class-gatherpress.php index dead962..6c6af0f 100644 --- a/includes/plugins/class-gatherpress.php +++ b/includes/plugins/class-gatherpress.php @@ -41,12 +41,12 @@ final class GatherPress extends Event_Plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { - return class_exists( '\GatherPress\Core\Utility' ) ? \GatherPress\Core\Utility::prefix_key( 'general' ) : 'gatherpress_general'; + public static function get_settings_pages(): array { + return array( class_exists( '\GatherPress\Core\Utility' ) ? \GatherPress\Core\Utility::prefix_key( 'general' ) : 'gatherpress_general' ); } /** diff --git a/includes/plugins/class-modern-events-calendar-lite.php b/includes/plugins/class-modern-events-calendar-lite.php index f8f5552..796634d 100644 --- a/includes/plugins/class-modern-events-calendar-lite.php +++ b/includes/plugins/class-modern-events-calendar-lite.php @@ -42,12 +42,12 @@ final class Modern_Events_Calendar_Lite extends Event_plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { - return 'mec-event'; + public static function get_settings_pages(): array { + return array( 'MEC-settings', 'MEC-support', 'MEC-ix', 'MEC-wizard', 'MEC-addons', 'mec-intro' ); } /** diff --git a/includes/plugins/class-the-events-calendar.php b/includes/plugins/class-the-events-calendar.php index ef07590..36ab8e0 100644 --- a/includes/plugins/class-the-events-calendar.php +++ b/includes/plugins/class-the-events-calendar.php @@ -41,17 +41,17 @@ final class The_Events_Calendar extends Event_plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { + public static function get_settings_pages(): array { if ( class_exists( '\Tribe\Events\Admin\Settings' ) ) { $page = \Tribe\Events\Admin\Settings::$settings_page_id; } else { $page = 'tec-events-settings'; } - return sprintf( 'edit.php?post_type=tribe_events&page=%s', $page ); + return array( $page ); } /** diff --git a/includes/plugins/class-vs-event-list.php b/includes/plugins/class-vs-event-list.php index 0e1b0dc..f1bd96b 100644 --- a/includes/plugins/class-vs-event-list.php +++ b/includes/plugins/class-vs-event-list.php @@ -44,12 +44,12 @@ final class VS_Event_List extends Event_Plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { - return 'settings_page_vsel'; + public static function get_settings_pages(): array { + return array( 'settings_page_vsel' ); } /** diff --git a/includes/plugins/class-wp-event-manager.php b/includes/plugins/class-wp-event-manager.php index e3d3493..28a852a 100644 --- a/includes/plugins/class-wp-event-manager.php +++ b/includes/plugins/class-wp-event-manager.php @@ -44,12 +44,12 @@ final class WP_Event_Manager extends Event_Plugin { } /** - * Returns the ID of the main settings page of the plugin. + * Returns the IDs of the admin pages of the plugin. * - * @return string The settings page url. + * @return array The settings page urls. */ - public static function get_settings_page(): string { - return 'event-manager-settings'; + public static function get_settings_pages(): array { + return array( 'event-manager-settings' ); } /** -- 2.39.5 From 10ea2f17d188ee3d8eddaa40b54d770bfd072440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 19 Oct 2024 14:23:06 +0200 Subject: [PATCH 4/6] add welcome message to status --- CHANGELOG.md | 12 +++++++++ assets/css/activitypub-event-bridge-admin.css | 17 ++++++++++++- templates/status.php | 25 ++++++++++++++++--- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9a605a7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0] - 2024-10-20 + +### Added + +* Initial version tag. diff --git a/assets/css/activitypub-event-bridge-admin.css b/assets/css/activitypub-event-bridge-admin.css index a3575c3..f3e6793 100644 --- a/assets/css/activitypub-event-bridge-admin.css +++ b/assets/css/activitypub-event-bridge-admin.css @@ -5,6 +5,20 @@ margin-bottom: 1.5em; } +.activitypub-event-bridge-settings-page .box ul.activitypub-event-bridge-list { + list-style-type: disc; + margin-left: 1rem; +} + +.activitypub-event-bridge-settings-page .box pre { + padding: 1rem; + min-height: 200px; + box-shadow: none; + border-radius: 15px; + border: 1px solid #dfe0e2; + background-color: #f7f7f7; +} + .activitypub-event-bridge-settings { max-width: 800px; margin: 0 auto; @@ -49,4 +63,5 @@ .activitypub-event-bridge-settings .box h3 { font-size: 1.1rem!important; -} \ No newline at end of file +} + diff --git a/templates/status.php b/templates/status.php index 36d8b74..2b5a04a 100644 --- a/templates/status.php +++ b/templates/status.php @@ -20,13 +20,30 @@ use ActivityPub_Event_Bridge\Setup; $active_event_plugins = Setup::get_instance()->get_active_event_plugins(); +global $wp_filesystem; +WP_Filesystem(); + ?>
-

- -

get_plugin_name() ); ?>

- +

+

+
    + +
  • get_plugin_name() ); ?>
  • + +
+
+ +
+

+
+			get_contents( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . '/CHANGELOG.md' );
+			echo esc_html( substr( $changelog, strpos( $changelog, "\n", 180 ) + 1 ) );
+			?>
+		
+ -- 2.39.5 From 52401380b2a952badd87d5ebfe58f77145370117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 19 Oct 2024 16:34:47 +0200 Subject: [PATCH 5/6] some improvements --- assets/css/activitypub-event-bridge-admin.css | 7 ++- includes/admin/class-health-check.php | 56 ++++++++++++++++++- includes/admin/class-settings-page.php | 6 +- includes/class-settings.php | 2 +- includes/class-setup.php | 2 +- templates/admin-header.php | 6 +- templates/settings.php | 4 ++ templates/{status.php => welcome.php} | 29 +++++++++- 8 files changed, 98 insertions(+), 14 deletions(-) rename templates/{status.php => welcome.php} (52%) diff --git a/assets/css/activitypub-event-bridge-admin.css b/assets/css/activitypub-event-bridge-admin.css index f3e6793..b6eaae1 100644 --- a/assets/css/activitypub-event-bridge-admin.css +++ b/assets/css/activitypub-event-bridge-admin.css @@ -6,8 +6,8 @@ } .activitypub-event-bridge-settings-page .box ul.activitypub-event-bridge-list { - list-style-type: disc; - margin-left: 1rem; + list-style-type: disc; + margin-left: 1.4rem; } .activitypub-event-bridge-settings-page .box pre { @@ -65,3 +65,6 @@ font-size: 1.1rem!important; } +#activitypub_event_bridge_initially_activated { + display: hidden; +} diff --git a/includes/admin/class-health-check.php b/includes/admin/class-health-check.php index efcc6c0..1f44905 100644 --- a/includes/admin/class-health-check.php +++ b/includes/admin/class-health-check.php @@ -7,8 +7,10 @@ namespace ActivityPub_Event_Bridge\Admin; +use Activitypub\Transformer\Factory as Transformer_Factory; +use ActivityPub_Event_Bridge\Plugins\Event_Plugin; use ActivityPub_Event_Bridge\Setup; -use WP_Error; +use WP_Query; /** * ActivityPub Health_Check Class. @@ -76,6 +78,58 @@ class Health_Check { return $result; } + /** + * Test if right transformer gets applied. + * + * @param Event_Plugin $event_plugin The event plugin definition. + * + * @return bool True if the check passed. + */ + public static function test_if_event_transformer_is_used( $event_plugin ) { + // Get a (random) event post. + $event_posts = self::get_most_recent_event_posts( $event_plugin->get_post_type(), 1 ); + + // If no post is found, we can not do this test. + if ( ! $event_posts || is_wp_error( $event_posts ) || empty( $event_posts ) ) { + return true; + } + + // Call the transformer Factory. + $transformer = Transformer_Factory::get_transformer( $event_posts[0] ); + // Check that we got the right transformer. + $desired_transformer_class = $event_plugin::get_activitypub_event_transformer_class(); + if ( $transformer instanceof $desired_transformer_class ) { + return true; + } + return false; + } + + /** + * Retrieves the most recently published event posts of a certain event post type. + * + * @param string $event_post_type The post type of the events. + * @param int $number_of_posts The maximum number of events to return. + * + * @return WP_Post[]|false Array of event posts, or false if none are found. + */ + public static function get_most_recent_event_posts( $event_post_type, $number_of_posts = 5 ) { + $args = array( + 'numberposts' => $number_of_posts, + 'category' => 0, + 'orderby' => 'date', + 'order' => 'DESC', + 'include' => array(), + 'exclude' => array(), + 'meta_key' => '', + 'meta_value' => '', + 'post_type' => $event_post_type, + 'suppress_filters' => true, + ); + + $query = new WP_Query(); + return $query->query( $args ); + } + /** * Transform the most recent event posts. */ diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php index 645495a..9694d98 100644 --- a/includes/admin/class-settings-page.php +++ b/includes/admin/class-settings-page.php @@ -91,7 +91,7 @@ class Settings_Page { public static function settings_page(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_GET['tab'] ) ) { - $tab = 'status'; + $tab = 'welcome'; } else { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tab = sanitize_key( $_GET['tab'] ); @@ -116,13 +116,13 @@ class Settings_Page { \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args ); break; - case 'status': + case 'welcome': default: wp_enqueue_script( 'plugin-install' ); add_thickbox(); wp_enqueue_script( 'updates' ); - \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/status.php', true ); + \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/welcome.php', true ); break; } } diff --git a/includes/class-settings.php b/includes/class-settings.php index 69ae58f..e5f69f0 100644 --- a/includes/class-settings.php +++ b/includes/class-settings.php @@ -68,7 +68,7 @@ class Settings { array( 'type' => 'boolean', 'description' => \__( 'Whether the plugin just got activated for the first time.', 'activitypub' ), - 'default' => true, + 'default' => 1, ) ); } diff --git a/includes/class-setup.php b/includes/class-setup.php index bfaef37..e9b602c 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -287,7 +287,7 @@ class Setup { * This method handles the activation of the ActivityPub Event Bridge plugin. * * @since 1.0.0 - * + * @see register_activation_hook() * @return void */ public function activate(): void { diff --git a/templates/admin-header.php b/templates/admin-header.php index 1890558..efc02bc 100644 --- a/templates/admin-header.php +++ b/templates/admin-header.php @@ -9,7 +9,7 @@ $args = wp_parse_args( $args, array( - 'status' => '', + 'welcome' => '', 'settings' => '', ) ); @@ -21,8 +21,8 @@ $args = wp_parse_args(
+ + diff --git a/templates/status.php b/templates/welcome.php similarity index 52% rename from templates/status.php rename to templates/welcome.php index 2b5a04a..3fbed43 100644 --- a/templates/status.php +++ b/templates/welcome.php @@ -9,12 +9,14 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore use ActivityPub_Event_Bridge\Setup; +use ActivityPub_Event_Bridge\Admin\Settings_Page; +use ActivityPub_Event_Bridge\Admin\Health_Check; \load_template( __DIR__ . '/admin-header.php', true, array( - 'status' => 'active', + 'welcome' => 'active', ) ); @@ -27,15 +29,34 @@ WP_Filesystem(); -- 2.39.5 From b329177fc6e4fa7eba46d6fdae4f4e1bd942e8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sat, 19 Oct 2024 16:36:42 +0200 Subject: [PATCH 6/6] phpcs --- includes/plugins/class-event-plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/plugins/class-event-plugin.php b/includes/plugins/class-event-plugin.php index f08b5c0..a5c5734 100644 --- a/includes/plugins/class-event-plugin.php +++ b/includes/plugins/class-event-plugin.php @@ -74,7 +74,7 @@ abstract class Event_Plugin { // Check if we are on a edit page for the event, or on the settings page of the event plugin. $is_event_plugins_edit_page = 'edit' === $screen->base && static::get_post_type() === $screen->post_type; - $is_event_plugins_settings_page = in_array( $screen->id, static::get_settings_pages(), true); + $is_event_plugins_settings_page = in_array( $screen->id, static::get_settings_pages(), true ); return $is_event_plugins_edit_page || $is_event_plugins_settings_page; } -- 2.39.5