diff --git a/inc/Engine/Common/PerformanceHints/WarmUp/Controller.php b/inc/Engine/Common/PerformanceHints/WarmUp/Controller.php index ce2a7bc762..61671d8c1d 100644 --- a/inc/Engine/Common/PerformanceHints/WarmUp/Controller.php +++ b/inc/Engine/Common/PerformanceHints/WarmUp/Controller.php @@ -69,7 +69,8 @@ private function is_allowed(): bool { return ! ( 'local' === wp_get_environment_type() || $this->user->is_license_expired_grace_period() || - (bool) $this->options->get( 'remove_unused_css', 0 ) + (bool) $this->options->get( 'remove_unused_css', 0 ) || + rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ); } diff --git a/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php b/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php index e7533f587d..8d8cdfaca2 100644 --- a/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php +++ b/inc/Engine/Optimization/LazyRenderContent/Frontend/Controller.php @@ -136,7 +136,7 @@ public function add_hashes_when_allowed( $html ) { * @return string */ public function add_hashes( $html ) { - if ( empty( $html ) ) { + if ( empty( $html ) || ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) && ! isset( $_GET['wpr_lazyrendercontent'] ) ) ) {// phpcs:ignore WordPress.Security.NonceVerification.Recommended return $html; } diff --git a/tests/Fixtures/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php b/tests/Fixtures/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php index 1c18725374..a1614f44b1 100644 --- a/tests/Fixtures/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php +++ b/tests/Fixtures/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php @@ -7,6 +7,7 @@ 'factories' => [1], 'license_expired' => false, 'home_url' => 'http://example.com/', + 'rocket_optimise' => false, ], 'expected' => 1, ], @@ -17,6 +18,7 @@ 'factories' => [1], 'license_expired' => true, 'home_url' => 'http://example.com/', + 'rocket_optimise' => false, ], 'expected' => 0, ], @@ -27,6 +29,7 @@ 'factories' => [1], 'license_expired' => false, 'home_url' => 'http://example.com/', + 'rocket_optimise' => false, ], 'expected' => 0, ], @@ -37,6 +40,7 @@ 'license_expired' => false, 'factories' => [1], 'home_url' => 'http://example.com/', + 'rocket_optimise' => false, ], 'expected' => 0, ], @@ -47,6 +51,18 @@ 'license_expired' => false, 'factories' => [], 'home_url' => 'http://example.com/', + 'rocket_optimise' => true, + ], + 'expected' => 0, + ], + 'testShouldNotCallSendToSaasWhenDonotRocketOptimiseIsTrue' => [ + 'config' => [ + 'wp_env' => 'production', + 'remove_unused_css' => 0, + 'factories' => [1], + 'license_expired' => false, + 'home_url' => 'http://example.com/', + 'rocket_optimise' => true, ], 'expected' => 0, ], diff --git a/tests/Fixtures/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php b/tests/Fixtures/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php index 7ba4a5967f..fb771790ab 100644 --- a/tests/Fixtures/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php +++ b/tests/Fixtures/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php @@ -80,5 +80,20 @@ 'html' => file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/html/expected_exclusions.php' ), ] ], + 'shouldNotAddHashesWhenDonotoptimize' => [ + 'config' => [ + 'donotrocketoptimize' => true, + 'row' => [ + 'url' => 'http://example.org/', + 'is_mobile' => 0, + 'below_the_fold' => json_encode([]), + 'status' => 'completed' + ], + 'html' => file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/html/original.php' ), + ], + 'expected' => [ + 'html' => file_get_contents( WP_ROCKET_TESTS_FIXTURES_DIR . '/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/html/original.php' ), + ] + ], ] ]; diff --git a/tests/Integration/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php b/tests/Integration/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php index df9703bc1c..4c71899a98 100644 --- a/tests/Integration/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php +++ b/tests/Integration/inc/Engine/Common/PerformanceHints/WarmUp/Subscriber/warmUpHome.php @@ -35,6 +35,14 @@ public function testShouldDoExpected( $config, $expected ) { Functions\expect( 'wp_get_environment_type' )->andReturn($config['wp_env']); + Functions\when('rocket_get_constant')->alias(function ($name, $default = null) use ($config) { + if('DONOTROCKETOPTIMIZE' === $name) { + return $config['rocket_optimise']; + } + + return $default; + }); + $queue->shouldReceive('add_job_warmup') ->times($expected); diff --git a/tests/Integration/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php b/tests/Integration/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php index 699cf7caf5..43110d44c6 100644 --- a/tests/Integration/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php +++ b/tests/Integration/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes.php @@ -46,6 +46,7 @@ public function tear_down() { */ public function testShouldWorkAsExpected( $config, $expected ) { self::addLrc( $config['row'] ); + $this->donotrocketoptimize = $config['donotrocketoptimize'] ?? null; add_filter( 'rocket_lrc_optimization', '__return_true' ); add_filter( 'rocket_lrc_exclusions', function() use ($config) {