Skip to content

Commit 139c42e

Browse files
committed
fix issues when the dam image urls tags don't have width/height by using the width/height arguments when present
1 parent 65a87ae commit 139c42e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

inc/app_replacer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@ protected function parse_dimensions_from_filename( $src ) {
612612
if ( $width && $height ) {
613613
return [ $width, $height, $crop ];
614614
}
615+
} else {
616+
$optimized_args = $this->parse_dimension_from_optimized_url( $src );
617+
if ( $optimized_args[0] !== 'auto' && $optimized_args[1] !== 'auto' ) {
618+
return [
619+
$optimized_args[0] !== 'auto' ? (int) $optimized_args[0] : false,
620+
$optimized_args[1] !== 'auto' ? (int) $optimized_args[1] : false,
621+
false,
622+
];
623+
}
615624
}
616625

617626
return [ false, false, false ];

inc/tag_replacer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
final class Optml_Tag_Replacer extends Optml_App_Replacer {
1010
use Optml_Normalizer;
1111
use Optml_Validator;
12+
use Optml_Dam_Offload_Utils;
1213

1314
/**
1415
* Cached object instance.

tests/test-lazyload.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Test_Lazyload extends WP_UnitTestCase {
2525
<img src="http://example.org/wp-content/optimole-wp/assets/img/logo5.gif">
2626
';
2727
const DAM_IMG_TAG = '<img width="100" height="200" src="https://cloudUrlTest.test/dam:1/w:auto/h:auto/q:auto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg">';
28+
const DAM_IMG_TAG_NO_WIDTH = '<img src="https://cloudUrlTest.test/w:200/h:300/process:20202/q:auto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg">';
2829
public function setUp() : void {
2930
parent::setUp();
3031
$settings = new Optml_Settings();
@@ -575,4 +576,13 @@ public function test_dam_lazyloading() {
575576

576577
$this->assertStringContainsString( 'data-opt-src="https://cloudUrlTest.test/w:100/h:200/rt:fill/g:ce/ig:avif/q:mauto/id:b1b12ee03bf3945d9d9bb963ce79cd4f/https://test-site.test/9.jpg"', $replaced_content );
577578
}
579+
public function test_dam_lazyloading_no_wh_attributes() {
580+
add_filter('optml_lazyload_images_skip','__return_zero');
581+
Optml_Manager::instance()->lazyload_replacer->settings->update('lazyload_placeholder','enabled');
582+
Optml_Manager::instance()->lazyload_replacer->init();
583+
$replaced_content = Optml_Manager::instance()->process_images_from_content( self::DAM_IMG_TAG_NO_WIDTH );
584+
$svg = Optml_Manager::instance()->lazyload_replacer->get_svg_for( 200, 300, 'http://example.org/testimage.png' );
585+
$this->assertStringContainsString( $svg, $replaced_content );
586+
remove_filter('optml_lazyload_images_skip','__return_zero');
587+
}
578588
}

0 commit comments

Comments
 (0)