Skip to content

Commit

Permalink
PR review modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Jan 20, 2025
1 parent 12c65f1 commit 7765036
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
9 changes: 7 additions & 2 deletions inc/Engine/Common/PerformanceHints/Frontend/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ private function inject_beacon( $html, $url, $is_mobile ): string {

// Create the script tag.
$script_tag = "<script data-name=\"wpr-wpr-beacon\" src='{$script_url}' async></script>"; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
$body_tag = strrpos( $html, '</body>' );

// Append the script tag just before the closing body tag.
return preg_replace( '/<\/body>/', $inline_script . $script_tag . '</body>', $html, 1 );
if ( false !== $body_tag ) {
// Append the script tag just before the last closing body tag especially in cases where there's an iframe.
$html = substr_replace( $html, $inline_script . $script_tag . '</body>', $body_tag, 7 );
}

return $html;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
<title>Test</title>
</head>
<body>
</body>
<body>
<iframe srcdoc="
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Iframe Content</title>
</head>
<body>
<header>
<h1>Iframe Header</h1>
</header>
</body>
</html>
" width="600" height="400" style="border:none;"></iframe>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
<title>Test</title>
</head>
<body>
<iframe srcdoc="
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Iframe Content</title>
</head>
<body>
<header>
<h1>Iframe Header</h1>
</header>
</body>
</html>
" width="600" height="400" style="border:none;"></iframe>
<script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<body>
</body>
</html>

0 comments on commit 7765036

Please sign in to comment.