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 (#7045)
  • Loading branch information
Khadreal authored Oct 25, 2024
1 parent 8c1fed9 commit 7555acd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/Engine/Common/PerformanceHints/Frontend/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ 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' ) ) {
if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) && empty( $_GET['wpr_imagedimensions'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return $html;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'shouldReturnOriginalWhenDonotoptimize' => [
'config' => [
'donotrocketoptimize' => true,
'sass_visit' => false,
'html' => $html_input,
'atf' => [
'row' => null,
Expand All @@ -81,6 +82,20 @@
],
'expected' => $html_input,
],
'shouldAddBeaconWhenDonotoptimizeAndSaaSVisit' => [
'config' => [
'donotrocketoptimize' => true,
'sass_visit' => true,
'html' => $html_input,
'atf' => [
'row' => null,
],
'lrc' => [
'row' => null,
],
],
'expected' => $html_output_with_beacon,
],
'shouldAddBeaconToPage' => [
'config' => [
'html' => $html_input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function testShouldReturnAsExpected( $config, $expected ) {
$_GET[ $config['query_string'] ] = 1;
}

if ( isset( $config['sass_visit'] ) ) {
$_GET[ 'wpr_imagedimensions' ] = $config['sass_visit'];
}

if ( ! empty( $config['atf']['row'] ) ) {
self::addLcp( $config['atf']['row'] );
}
Expand Down

0 comments on commit 7555acd

Please sign in to comment.