Skip to content

Commit

Permalink
Fixes #6972 Prevent injecting Beacon script when DONOTROCKETOPTIMIZE …
Browse files Browse the repository at this point in the history
…is defined (#7022)
  • Loading branch information
remyperona authored Oct 15, 2024
1 parent d4a50ba commit 7f4f533
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inc/Engine/Common/PerformanceHints/Frontend/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public function maybe_apply_optimizations( string $html ): string {
* @return string The modified HTML content with the beacon script injected just before the closing body tag.
*/
private function inject_beacon( $html, $url, $is_mobile ): string {
if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) {
return $html;
}

$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

if ( ! $this->filesystem->exists( rocket_get_constant( 'WP_ROCKET_ASSETS_JS_PATH' ) . 'wpr-beacon' . $min . '.js' ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
],
'expected' => $html_input,
],
'shouldReturnOriginalWhenDonotoptimize' => [
'config' => [
'donotrocketoptimize' => true,
'html' => $html_input,
'atf' => [
'row' => null,
],
'lrc' => [
'row' => null,
],
],
'expected' => $html_input,
],
'shouldAddBeaconToPage' => [
'config' => [
'html' => $html_input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function tear_down() {
public function testShouldReturnAsExpected( $config, $expected ) {
$this->config = $config;
$this->cached_user = $config['user_cache_enabled'] ?? false;
$this->donotrocketoptimize = $config['donotrocketoptimize'] ?? null;

if ( isset( $config['query_string'] ) ) {
$_GET[ $config['query_string'] ] = 1;
Expand Down

0 comments on commit 7f4f533

Please sign in to comment.