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] 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(