diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php index 88303e955b..f7390cc681 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Controller.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Controller.php @@ -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( '##', $html, $matches ) ) { return $html; } diff --git a/inc/Engine/Media/AboveTheFold/Frontend/Subscriber.php b/inc/Engine/Media/AboveTheFold/Frontend/Subscriber.php index 17acbec472..949ed7f8c2 100644 --- a/inc/Engine/Media/AboveTheFold/Frontend/Subscriber.php +++ b/inc/Engine/Media/AboveTheFold/Frontend/Subscriber.php @@ -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 ], ]; } diff --git a/inc/Engine/Media/ImageDimensions/Subscriber.php b/inc/Engine/Media/ImageDimensions/Subscriber.php index 446c800bf9..43503c2f6b 100755 --- a/inc/Engine/Media/ImageDimensions/Subscriber.php +++ b/inc/Engine/Media/ImageDimensions/Subscriber.php @@ -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', ]; } @@ -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 * @@ -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' ] ); } }