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 @@ + + +