From 293c58bdbb7ea564029e8523ebf34b2e963b7453 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Fri, 23 Aug 2024 16:08:41 +0100 Subject: [PATCH] Fixes #6898 'Clear performance Hints data' in the WPR admin dropdown menu when env is set to local (#6899) --- inc/Engine/Admin/Settings/AdminBarMenuTrait.php | 15 --------------- inc/Engine/Saas/Admin/AdminBar.php | 16 ++++++++++++++++ .../AdminBar/addCleanPerformanceHintsItem.php | 11 ----------- .../addPerformanceHintsClearUrlMenuItem.php | 7 +++++-- .../AdminBar/addCleanPerformanceHintsItem.php | 2 -- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/inc/Engine/Admin/Settings/AdminBarMenuTrait.php b/inc/Engine/Admin/Settings/AdminBarMenuTrait.php index 38454038d3..f13127b2fe 100644 --- a/inc/Engine/Admin/Settings/AdminBarMenuTrait.php +++ b/inc/Engine/Admin/Settings/AdminBarMenuTrait.php @@ -24,10 +24,6 @@ protected function add_menu_to_admin_bar( return; } - if ( 'local' === wp_get_environment_type() ) { - return; - } - if ( ! is_admin() ) { return; } @@ -67,9 +63,6 @@ protected function add_url_menu_item_to_admin_bar( bool $context ) { global $post; - if ( 'local' === wp_get_environment_type() && $context ) { - return; - } if ( is_admin() ) { return; @@ -123,14 +116,6 @@ protected function add_url_menu_item_to_admin_bar( * @return void */ public function dashboard_button( bool $context, string $title, string $label, string $action, string $hover_text = '' ): void { - if ( - 'local' === wp_get_environment_type() - && - $context - ) { - return; - } - if ( ! $context ) { return; } diff --git a/inc/Engine/Saas/Admin/AdminBar.php b/inc/Engine/Saas/Admin/AdminBar.php index b078bb684f..86c53a62ef 100644 --- a/inc/Engine/Saas/Admin/AdminBar.php +++ b/inc/Engine/Saas/Admin/AdminBar.php @@ -51,6 +51,10 @@ public function add_clean_saas_menu_item( $wp_admin_bar ) { $title = __( 'Clear RUCSS optimizations', 'rocket' ); $action = 'rocket_clean_saas'; + if ( 'local' === wp_get_environment_type() ) { + return; + } + if ( 'local' === wp_get_environment_type() && @@ -79,6 +83,10 @@ public function add_clean_saas_menu_item( $wp_admin_bar ) { * @return void */ public function add_clean_url_menu_item( WP_Admin_Bar $wp_admin_bar ) { + if ( 'local' === wp_get_environment_type() && $this->rucss_url_context->is_allowed() ) { + return; + } + global $post; /** @@ -112,6 +120,14 @@ public function add_clean_url_menu_item( WP_Admin_Bar $wp_admin_bar ) { * @return void */ public function display_dashboard_button() { + if ( + 'local' === wp_get_environment_type() + && + $this->rucss_url_context->is_allowed() + ) { + return; + } + $this->dashboard_button( $this->rucss_url_context->is_allowed(), __( 'Remove Unused CSS', 'rocket' ), diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php index 9af0871f87..23e2859ace 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php @@ -54,17 +54,6 @@ 'title' => 'Clear Performance Hints data', ], ], - 'testShouldReturnNullWhenLocalEnvironment' => [ - 'config' => [ - 'rocket_valid_key' => true, - 'environment' => 'local', - 'is_admin' => false, - 'atf_context' => false, - 'lrc_context' => false, - 'current_user_can' => true, - ], - 'expected' => null, - ], 'testShouldReturnNullWhenNotAdmin' => [ 'config' => [ 'rocket_valid_key' => true, diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addPerformanceHintsClearUrlMenuItem.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addPerformanceHintsClearUrlMenuItem.php index 360be8484d..704cb02e83 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addPerformanceHintsClearUrlMenuItem.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addPerformanceHintsClearUrlMenuItem.php @@ -1,7 +1,7 @@ [ + 'testShouldReturnMenuWhenLocalEnvironment' => [ 'config' => [ 'environment' => 'local', 'is_admin' => false, @@ -12,7 +12,10 @@ 'can_display_options' => true, 'factories' => true, ], - 'expected' => null, + 'expected' => [ + 'id' => 'clear-performance-hints-data-url', + 'title' => 'Clear Performance Hints data of this URL', + ], ], 'testShouldReturnNullWhenAdmin' => [ 'config' => [ diff --git a/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php b/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php index 7e0eeccb54..55784aa6e1 100644 --- a/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php +++ b/tests/Unit/inc/Engine/Common/PerformanceHints/Admin/AdminBar/addCleanPerformanceHintsItem.php @@ -51,8 +51,6 @@ protected function setUp(): void { public function testShouldDoExpected( $config, $expected ) { Functions\when( 'rocket_valid_key' ) ->justReturn( $config['rocket_valid_key'] ); - Functions\when( 'wp_get_environment_type' ) - ->justReturn( $config['environment'] ); Functions\when( 'is_admin' ) ->justReturn( $config['is_admin'] );