Skip to content

Commit 48d0d6c

Browse files
fix: do not replace image with picture when viewing from a pagebuilder
1 parent 3df4bd5 commit 48d0d6c

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/class-tiny-helpers.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
class Tiny_Helpers {
2222

23+
2324
/**
2425
* truncate_text will truncate a string to a given length.
2526
* When text is longer than the given length, the string will be truncated and
@@ -108,4 +109,32 @@ public static function get_mimetype( $input ) {
108109
throw new Exception( 'finfo extension is not available.' );
109110
}
110111
}
112+
113+
114+
/**
115+
* Checks wether a user is viewing from a page builder
116+
*/
117+
public static function is_pagebuilder_request() {
118+
$pagebuilder_keys = array(
119+
'fl_builder', // Beaver Builder
120+
'et_fb', // Divi Builder
121+
'bricks', // Bricks Builder
122+
'breakdance', // Breakdance Builder
123+
'breakdance_browser', // Breakdance Builder
124+
'ct_builder', // Oxygen Builder
125+
'fb-edit', // Avada Live Builder
126+
'spio_no_cdn', // Site Origin
127+
'tatsu', // Tatsu Builder
128+
'tve', // Thrive Architect
129+
'tcbf', // Thrive Architect
130+
);
131+
132+
foreach ( $pagebuilder_keys as $key ) {
133+
if ( isset( $_GET[ $key ] ) ) {
134+
return true;
135+
}
136+
}
137+
138+
return false;
139+
}
111140
}

src/class-tiny-picture.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Tiny_Picture extends Tiny_WP_Base {
3131

3232

3333

34+
3435
/** @var string */
3536
private $base_dir;
3637

@@ -59,6 +60,10 @@ function __construct( $base_dir = ABSPATH, $domains = array() ) {
5960
return;
6061
}
6162

63+
if ( Tiny_Helpers::is_pagebuilder_request() ) {
64+
return;
65+
}
66+
6267
add_action('template_redirect', function () {
6368
ob_start( array( $this, 'replace_sources' ), 1000 );
6469
});
@@ -189,6 +194,7 @@ private function filter_images( $content ) {
189194
abstract class Tiny_Source_Base {
190195

191196

197+
192198
public $raw_html;
193199
protected $base_dir;
194200
protected $allowed_domains;
@@ -237,9 +243,9 @@ protected function get_element_by_tag( $html, $tagname ) {
237243
$regex_tag = preg_quote( $tagname, '~' );
238244
if ( preg_match_all(
239245
'~<' . $regex_tag .
240-
'\b(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>.*?</' .
241-
$regex_tag .
242-
'>~is',
246+
'\b(?:[^>"\']+|"[^"]*"|\'[^\']*\')*>.*?</' .
247+
$regex_tag .
248+
'>~is',
243249
$html,
244250
$matches
245251
) ) {
@@ -379,11 +385,13 @@ protected function create_alternative_sources( $original_source_html ) {
379385
}
380386
}
381387

382-
if ( $width_descriptor &&
388+
if (
389+
$width_descriptor &&
383390
! self::srcset_contains_width_descriptor(
384391
$srcset_parts,
385392
$width_descriptor
386-
) ) {
393+
)
394+
) {
387395
continue;
388396
}
389397

@@ -412,7 +420,7 @@ protected function create_alternative_sources( $original_source_html ) {
412420
}
413421
$source_parts[] = '/>';
414422
$sources[] = implode( ' ', $source_parts );
415-
}// End foreach().
423+
} // End foreach().
416424

417425
return $sources;
418426
}
@@ -472,6 +480,7 @@ class Tiny_Picture_Source extends Tiny_Source_Base {
472480

473481

474482

483+
475484
/**
476485
* Adds alternative format sources (e.g., image/webp, image/avif) to an existing
477486
* <picture> element based on locally available converted files.
@@ -513,6 +522,7 @@ public function augment_picture_element() {
513522

514523
class Tiny_Image_Source extends Tiny_Source_Base {
515524

525+
516526
/**
517527
* Generates a formatted image source array if the corresponding local file exists.
518528
*

0 commit comments

Comments
 (0)