wip on status and health check pages
All checks were successful
All checks were successful
This commit is contained in:
parent
7e8346cf7b
commit
dee2bf6b3e
5 changed files with 187 additions and 14 deletions
127
includes/admin/class-health-check.php
Normal file
127
includes/admin/class-health-check.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/**
|
||||
* Health_Check class.
|
||||
*
|
||||
* @package Activitypub_Event_Bridge
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Admin;
|
||||
|
||||
use ActivityPub_Event_Bridge\Setup;
|
||||
use WP_Error;
|
||||
|
||||
/**
|
||||
* ActivityPub Health_Check Class.
|
||||
*/
|
||||
class Health_Check {
|
||||
/**
|
||||
* Initialize health checks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'site_status_tests', array( self::class, 'add_tests' ) );
|
||||
\add_filter( 'debug_information', array( self::class, 'add_debug_information' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tests to the Site Health Check.
|
||||
*
|
||||
* @param array $tests The test array.
|
||||
*
|
||||
* @return array The filtered test array.
|
||||
*/
|
||||
public static function add_tests( $tests ) {
|
||||
$tests['direct']['activitypub_event_bridge_test'] = array(
|
||||
'label' => __( '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(
|
||||
'<p>%s</p>',
|
||||
\__( '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(
|
||||
'<p>%s</p>',
|
||||
$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;
|
||||
}
|
||||
}
|
|
@ -89,6 +89,16 @@ class Settings_Page {
|
|||
* @return void
|
||||
*/
|
||||
public static function settings_page(): void {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( empty( $_GET['tab'] ) ) {
|
||||
$tab = 'status';
|
||||
} else {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$tab = sanitize_key( $_GET['tab'] );
|
||||
}
|
||||
|
||||
switch ( $tab ) {
|
||||
case 'settings':
|
||||
$plugin_setup = Setup::get_instance();
|
||||
|
||||
$event_plugins = $plugin_setup->get_active_event_plugins();
|
||||
|
@ -105,5 +115,15 @@ class Settings_Page {
|
|||
);
|
||||
|
||||
\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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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(
|
||||
|
|
15
templates/status.php
Normal file
15
templates/status.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Status page for the ActivityPub Event Bridge.
|
||||
*
|
||||
* @package ActivityPub_Event_Bridge
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<div class="activitypub-event-bridge-settings-page hide-if-no-js">
|
||||
<div class="box">
|
||||
<h2><?php \esc_html_e( 'Status', 'activitypub-event-bridge' ); ?></h2>
|
||||
<p>This is so cool!</p>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue