some improvements
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 48s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m9s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m5s

This commit is contained in:
André Menrath 2024-10-19 16:34:47 +02:00
parent 10ea2f17d1
commit 52401380b2
8 changed files with 98 additions and 14 deletions

View file

@ -6,8 +6,8 @@
} }
.activitypub-event-bridge-settings-page .box ul.activitypub-event-bridge-list { .activitypub-event-bridge-settings-page .box ul.activitypub-event-bridge-list {
list-style-type: disc; list-style-type: disc;
margin-left: 1rem; margin-left: 1.4rem;
} }
.activitypub-event-bridge-settings-page .box pre { .activitypub-event-bridge-settings-page .box pre {
@ -65,3 +65,6 @@
font-size: 1.1rem!important; font-size: 1.1rem!important;
} }
#activitypub_event_bridge_initially_activated {
display: hidden;
}

View file

@ -7,8 +7,10 @@
namespace ActivityPub_Event_Bridge\Admin; 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 ActivityPub_Event_Bridge\Setup;
use WP_Error; use WP_Query;
/** /**
* ActivityPub Health_Check Class. * ActivityPub Health_Check Class.
@ -76,6 +78,58 @@ class Health_Check {
return $result; 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. * Transform the most recent event posts.
*/ */

View file

@ -91,7 +91,7 @@ class Settings_Page {
public static function settings_page(): void { public static function settings_page(): void {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( empty( $_GET['tab'] ) ) { if ( empty( $_GET['tab'] ) ) {
$tab = 'status'; $tab = 'welcome';
} else { } else {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = sanitize_key( $_GET['tab'] ); $tab = sanitize_key( $_GET['tab'] );
@ -116,13 +116,13 @@ class Settings_Page {
\load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args ); \load_template( ACTIVITYPUB_EVENT_BRIDGE_PLUGIN_DIR . 'templates/settings.php', true, $args );
break; break;
case 'status': case 'welcome':
default: default:
wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'plugin-install' );
add_thickbox(); add_thickbox();
wp_enqueue_script( 'updates' ); 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; break;
} }
} }

View file

@ -68,7 +68,7 @@ class Settings {
array( array(
'type' => 'boolean', 'type' => 'boolean',
'description' => \__( 'Whether the plugin just got activated for the first time.', 'activitypub' ), 'description' => \__( 'Whether the plugin just got activated for the first time.', 'activitypub' ),
'default' => true, 'default' => 1,
) )
); );
} }

View file

@ -287,7 +287,7 @@ class Setup {
* This method handles the activation of the ActivityPub Event Bridge plugin. * This method handles the activation of the ActivityPub Event Bridge plugin.
* *
* @since 1.0.0 * @since 1.0.0
* * @see register_activation_hook()
* @return void * @return void
*/ */
public function activate(): void { public function activate(): void {

View file

@ -9,7 +9,7 @@
$args = wp_parse_args( $args = wp_parse_args(
$args, $args,
array( array(
'status' => '', 'welcome' => '',
'settings' => '', 'settings' => '',
) )
); );
@ -21,8 +21,8 @@ $args = wp_parse_args(
</div> </div>
<nav class="activitypub-event-bridge-settings-tabs-wrapper" aria-label="<?php \esc_attr_e( 'Secondary menu', 'activitypub-event-bridge' ); ?>"> <nav class="activitypub-event-bridge-settings-tabs-wrapper" aria-label="<?php \esc_attr_e( 'Secondary menu', 'activitypub-event-bridge' ); ?>">
<a href="<?php echo \esc_url( admin_url( 'options-general.php?page=activitypub-event-bridge' ) ); ?>" class="activitypub-event-bridge-settings-tab <?php echo \esc_attr( $args['status'] ); ?>"> <a href="<?php echo \esc_url( admin_url( 'options-general.php?page=activitypub-event-bridge' ) ); ?>" class="activitypub-event-bridge-settings-tab <?php echo \esc_attr( $args['welcome'] ); ?>">
<?php \esc_html_e( 'Status', 'activitypub-event-bridge' ); ?> <?php \esc_html_e( 'Welcome', 'activitypub-event-bridge' ); ?>
</a> </a>
<a href="<?php echo \esc_url( admin_url( 'options-general.php?page=activitypub-event-bridge&tab=settings' ) ); ?>" class="activitypub-event-bridge-settings-tab <?php echo \esc_attr( $args['settings'] ); ?>"> <a href="<?php echo \esc_url( admin_url( 'options-general.php?page=activitypub-event-bridge&tab=settings' ) ); ?>" class="activitypub-event-bridge-settings-tab <?php echo \esc_attr( $args['settings'] ); ?>">

View file

@ -97,6 +97,10 @@ $current_category_mapping = \get_option( 'activitypub_event_bridge_event_
</table> </table>
<?php endif; ?> <?php endif; ?>
</div> </div>
<!-- This disables the setup wizard. -->
<div class="hidden">
<input type="checkbox" id="activitypub_event_bridge_initially_activated" name="activitypub_event_bridge_initially_activated"/>
</div>
<?php \submit_button(); ?> <?php \submit_button(); ?>
</form> </form>
</div> </div>

View file

@ -9,12 +9,14 @@
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use ActivityPub_Event_Bridge\Setup; use ActivityPub_Event_Bridge\Setup;
use ActivityPub_Event_Bridge\Admin\Settings_Page;
use ActivityPub_Event_Bridge\Admin\Health_Check;
\load_template( \load_template(
__DIR__ . '/admin-header.php', __DIR__ . '/admin-header.php',
true, true,
array( array(
'status' => 'active', 'welcome' => 'active',
) )
); );
@ -27,15 +29,34 @@ WP_Filesystem();
<div class="activitypub-event-bridge-settings activitypub-event-bridge-settings-page hide-if-no-js"> <div class="activitypub-event-bridge-settings activitypub-event-bridge-settings-page hide-if-no-js">
<div class="box"> <div class="box">
<h2><?php \esc_html_e( 'Welcome', 'activitypub-event-bridge' ); ?></h2> <h2><?php \esc_html_e( 'Status', 'activitypub-event-bridge' ); ?></h2>
<p><?php \esc_html_e( 'The ActivityPub Event Bridge detected the following (activated) event plugins:', 'activitypub-event-bridge' ); ?></p> <p><?php \esc_html_e( 'The ActivityPub Event Bridge detected the following (activated) event plugins:', 'activitypub-event-bridge' ); ?></p>
<ul class="activitypub-event-bridge-list"> <ul class="activitypub-event-bridge-list">
<?php foreach ( $active_event_plugins as $active_event_plugin ) { ?> <?php foreach ( $active_event_plugins as $active_event_plugin ) { ?>
<li><?php echo esc_html( $active_event_plugin->get_plugin_name() ); ?> </li> <li>
<strong><?php echo esc_html( $active_event_plugin->get_plugin_name() ); ?>:</strong>
<br>
<?php
if ( Health_Check::test_if_event_transformer_is_used( $active_event_plugin ) ) {
echo 'The ActivityPub Event Bridge successfully registered to the ActivityPub plugin.';
} else {
echo 'The ActivityPub Event Bridge could not register to the ActivityPub plugin.';
}
?>
</li>
<?php } ?> <?php } ?>
</ul> </ul>
</div> </div>
<?php if ( get_option( 'activitypub_event_bridge_initially_activated', true ) ) : ?>
<a href="<?php echo esc_url( admin_url( 'options-general.php?page=' . Settings_Page::SETTINGS_SLUG ) . '&tab=settings' ); ?>" role="button">
<button class="button button-primary">
<strong></strong> <?php \esc_html_e( 'Continue your setup', 'activitypub-event-bridge' ); ?>
</button>
</a>
<?php else : ?>
<div class="box"> <div class="box">
<h2><?php \esc_html_e( 'Changelog', 'activitypub-event-bridge' ); ?></h2> <h2><?php \esc_html_e( 'Changelog', 'activitypub-event-bridge' ); ?></h2>
<pre> <pre>
@ -45,5 +66,7 @@ WP_Filesystem();
?> ?>
</pre> </pre>
</div> </div>
<?php endif; ?>
</div> </div>