diff --git a/includes/class-admin.php b/includes/class-admin.php index 355b6336c..b0e9934b4 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -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' ) ); @@ -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 ) { + ?> -
-

-
+
+

+
- 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 ) { diff --git a/tests/test-class-admin.php b/tests/test-class-admin.php index 3ffddc679..73db3beeb 100644 --- a/tests/test-class-admin.php +++ b/tests/test-class-admin.php @@ -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/" ); @@ -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" );