Skip to content

Commit

Permalink
Closes #6518: Inject beacon for saas visit
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Apr 9, 2024
1 parent b459f19 commit 471ad6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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

Check notice on line 96 in inc/Engine/Media/AboveTheFold/Frontend/Controller.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/AboveTheFold/Frontend/Controller.php#L96

Inline comments must end in full-stops, exclamation marks, or question marks
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
19 changes: 18 additions & 1 deletion inc/Engine/Media/ImageDimensions/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ 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'] ) ) { // Bail out if wpr_imagedimensions is not set

Check notice on line 75 in inc/Engine/Media/ImageDimensions/Subscriber.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/ImageDimensions/Subscriber.php#L75

Inline comments must end in full-stops, exclamation marks, or question marks

Check notice on line 75 in inc/Engine/Media/ImageDimensions/Subscriber.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/ImageDimensions/Subscriber.php#L75

Processing form data without nonce verification.
return $buffer;
}

do_action( 'rocket_critical_image_saas_visit_buffer', $buffer ); // Fire an action

Check notice on line 79 in inc/Engine/Media/ImageDimensions/Subscriber.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

inc/Engine/Media/ImageDimensions/Subscriber.php#L79

Inline comments must end in full-stops, exclamation marks, or question marks

return $this->dimensions->specify_image_dimensions( $buffer );
}

/**
* Start image dimensions buffer to add
*
Expand All @@ -80,6 +97,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' ] );
}
}

0 comments on commit 471ad6d

Please sign in to comment.