Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6518: inject beacon for saas #6548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions inc/Engine/Media/AboveTheFold/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public function lcp( $html ): string {
* @return string
*/
private function preload_lcp( $html, $row ) {
if ( rocket_bypass() ) { // Bail out if rocket_bypass() returns true.
return $html;
}

if ( ! preg_match( '#</title\s*>#', $html, $matches ) ) {
return $html;
}
Expand Down
5 changes: 3 additions & 2 deletions inc/Engine/Media/AboveTheFold/Frontend/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function __construct( Controller $controller ) {
*/
public static function get_subscribed_events() {
return [
'rocket_buffer' => [ 'lcp', 17 ],
'rocket_lazyload_excluded_src' => 'add_exclusions',
'rocket_buffer' => [ 'lcp', 17 ],
'rocket_lazyload_excluded_src' => 'add_exclusions',
'rocket_critical_image_saas_visit_buffer' => [ 'lcp', 17 ],
];
}

Expand Down
22 changes: 19 additions & 3 deletions inc/Engine/Media/ImageDimensions/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public function __construct( ImageDimensions $dimensions, Tests $buffer_tests )
*/
public static function get_subscribed_events() {
return [
'rocket_buffer' => [ 'specify_image_dimensions', 17 ],
'template_redirect' => [ 'start_image_dimensions_buffer', 3 ],
'rocket_buffer' => [ 'specify_image_dimensions', 17 ],
'template_redirect' => [ 'start_image_dimensions_buffer', 3 ],
'rocket_critical_image_saas_visit_buffer' => 'specify_image_dimensions',
];
}

Expand All @@ -64,6 +65,21 @@ public function specify_image_dimensions( $buffer ) {
return $this->dimensions->specify_image_dimensions( $buffer );
}

/**
* Update images that have no width/height with real dimentions for the SaaS
*
* @param string $buffer Page HTML content.
*
* @return string Page HTML content after update.
*/
public function prepare_critical_image_saas_visit( $buffer ) {
if ( ! isset( $_GET['wpr_imagedimensions'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return $buffer;
}

return apply_filters( 'rocket_critical_image_saas_visit_buffer', $buffer );
}

/**
* Start image dimensions buffer to add
*
Expand All @@ -80,6 +96,6 @@ public function start_image_dimensions_buffer() {

add_filter( 'rocket_specify_image_dimensions', '__return_true' );

ob_start( [ $this, 'specify_image_dimensions' ] );
ob_start( [ $this, 'prepare_critical_image_saas_visit' ] );
}
}
Loading