Skip to content

Commit

Permalink
Fixes #6898 'Clear performance Hints data' in the WPR admin dropdown …
Browse files Browse the repository at this point in the history
…menu when env is set to local (#6899)
  • Loading branch information
Khadreal authored Aug 23, 2024
1 parent c6b849e commit 293c58b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
15 changes: 0 additions & 15 deletions inc/Engine/Admin/Settings/AdminBarMenuTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ protected function add_menu_to_admin_bar(
return;
}

if ( 'local' === wp_get_environment_type() ) {
return;
}

if ( ! is_admin() ) {
return;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions inc/Engine/Saas/Admin/AdminBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
&&
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'testShouldReturnNullWhenLocalEnvironment' => [
'testShouldReturnMenuWhenLocalEnvironment' => [
'config' => [
'environment' => 'local',
'is_admin' => false,
Expand All @@ -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' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );

Expand Down

0 comments on commit 293c58b

Please sign in to comment.