Skip to content

Commit

Permalink
remove calculation of static array of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Exon committed Dec 21, 2023
1 parent a92901a commit 54ba24d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
33 changes: 12 additions & 21 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public static function init() {
\add_action( 'admin_init', array( self::class, 'register_settings' ) );
\add_action( 'personal_options_update', array( self::class, 'save_user_description' ) );
\add_action( 'admin_enqueue_scripts', array( self::class, 'enqueue_scripts' ) );

self::$admin_notices = self::get_admin_notices();
if ( ! empty( self::$admin_notices ) ) {
\add_action( 'admin_notices', array( self::class, 'show_admin_notices' ) );
}
\add_action( 'admin_notices', array( self::class, 'admin_notices' ) );

if ( ! is_user_disabled( get_current_user_id() ) ) {
\add_action( 'show_user_profile', array( self::class, 'add_profile' ) );
Expand Down Expand Up @@ -54,32 +50,27 @@ public static function admin_menu() {
}

/**
* Collect admin menu notices about configuration problems or conflicts
* Display admin menu notices about configuration problems or conflicts
*/
public static function get_admin_notices() {
$admin_notices = array();

public static function admin_notices() {
$permalink_structure = \get_option( 'permalink_structure' );
if ( empty( $permalink_structure ) ) {
array_push( $admin_notices, 'You are using the ActivityPub plugin without setting a permalink structure. This will prevent ActivityPub from working. Please set a permalink structure.' );
$admin_notice = \__( 'You are using the ActivityPub plugin without setting a permalink structure. This will prevent ActivityPub from working. Please set a permalink structure.', 'activitypub' );
self::show_admin_notice( $admin_notice, 'error' );
}

return $admin_notices;
}

/**
* Display admin menu notices about configuration problems or conflicts
* Display one admin menu notice about configuration problems or conflicts
*/
public static function show_admin_notices() {
foreach ( self::$admin_notices as $admin_notice ) {
?>
private static function show_admin_notice( $admin_notice, $level ) {
?>

<div class="notice notice-error">
<p><?php echo wp_kses( $admin_notice, 'data' ); ?></p>
</div>
<div class="notice notice-<?php echo wp_kses( $level, 'data' ); ?>">
<p><?php echo wp_kses( $admin_notice, 'data' ); ?></p>
</div>

<?php
}
<?php
}

/**
Expand Down
28 changes: 12 additions & 16 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,18 @@ public static function add_data() {
}

public static function register_blocks() {
if ( ! \WP_Block_Type_Registry::get_instance()->is_registered( 'activitypub/followers' ) ) {
\register_block_type_from_metadata(
ACTIVITYPUB_PLUGIN_DIR . '/build/followers',
array(
'render_callback' => array( self::class, 'render_follower_block' ),
)
);
}
if ( ! \WP_Block_Type_Registry::get_instance()->is_registered( 'activitypub/follow-me' ) ) {
\register_block_type_from_metadata(
ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me',
array(
'render_callback' => array( self::class, 'render_follow_me_block' ),
)
);
}
\register_block_type_from_metadata(
ACTIVITYPUB_PLUGIN_DIR . '/build/followers',
array(
'render_callback' => array( self::class, 'render_follower_block' ),
)
);
\register_block_type_from_metadata(
ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me',
array(
'render_callback' => array( self::class, 'render_follow_me_block' ),
)
);
}

private static function get_user_id( $user_string ) {
Expand Down
2 changes: 0 additions & 2 deletions tests/test-class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
class Test_Admin extends WP_UnitTestCase {
public function test_no_permalink_structure_has_errors() {
\add_option( 'permalink_structure', '' );
\do_action( 'init' );
\do_action( 'admin_notices' );
$this->expectOutputRegex( "/notice-error/" );

Expand All @@ -11,7 +10,6 @@ public function test_no_permalink_structure_has_errors() {

public function test_has_permalink_structure_no_errors() {
\add_option( 'permalink_structure', '/archives/%post_id%' );
\do_action( 'init' );
\do_action( 'admin_notices' );
$this->expectOutputRegex( "/^((?!notice-error).)*$/s" );

Expand Down

0 comments on commit 54ba24d

Please sign in to comment.