Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion includes/class-openclawp-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public static function maybe_render_welcome_notice(): void {
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only page check.
$current_page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( (string) $_GET['page'] ) ) : '';
if ( self::PAGE_SLUG === $current_page ) {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! self::should_render_welcome_notice( $current_page, $screen ) ) {
return;
}

Expand All @@ -108,6 +109,31 @@ public static function maybe_render_welcome_notice(): void {
<?php
}

/**
* Decide whether the welcome notice should render for the current admin screen.
*
* @param string $current_page Current `page` query arg, if any.
* @param mixed $screen Current admin screen when available.
* @return bool
*/
private static function should_render_welcome_notice( string $current_page, $screen ): bool {
if ( self::PAGE_SLUG === $current_page ) {
return false;
}

/**
* Filters whether the first-run setup notice should render.
*
* Consumers with their own focused admin surfaces can return false for
* specific screens while still leaving openclaWP's setup wizard available.
*
* @param bool $show Whether to show the setup notice.
* @param string $current_page Current `page` query arg, if any.
* @param mixed $screen Current admin screen when available.
*/
return (bool) apply_filters( 'openclawp_show_setup_notice', true, $current_page, $screen );
}

/**
* Render the current wizard step. Each step is a self-contained card; the
* step is selected by `?step=` and defaults to step 1.
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/SetupWizardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Unit tests for OpenclaWP_Setup_Wizard.
*
* @package OpenclaWP\Tests
*/

declare( strict_types=1 );

namespace OpenclaWP\Tests\Unit;

use OpenclaWP_Setup_Wizard;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

/**
* @covers OpenclaWP_Setup_Wizard
*/
final class SetupWizardTest extends TestCase {

protected function tearDown(): void {
unset( $GLOBALS['openclawp_test_filters']['openclawp_show_setup_notice'] );
parent::tearDown();
}

public function test_welcome_notice_is_hidden_on_setup_page(): void {
$this->assertFalse( self::should_render_welcome_notice( 'openclawp-setup', null ) );
}

public function test_welcome_notice_can_be_hidden_by_filter_for_host_screen(): void {
$screen = (object) array( 'id' => 'toplevel_page_wp-inbox' );

$GLOBALS['openclawp_test_filters']['openclawp_show_setup_notice'] = static function ( bool $show, string $current_page, $passed_screen ) use ( $screen ): bool {
TestCase::assertTrue( $show );
TestCase::assertSame( 'wp-inbox', $current_page );
TestCase::assertSame( $screen, $passed_screen );
return false;
};

$this->assertFalse( self::should_render_welcome_notice( 'wp-inbox', $screen ) );
}

private static function should_render_welcome_notice( string $current_page, $screen ): bool {
$method = new ReflectionMethod( OpenclaWP_Setup_Wizard::class, 'should_render_welcome_notice' );
$method->setAccessible( true );

return (bool) $method->invoke( null, $current_page, $screen );
}
}
Loading