@@ -65,7 +65,6 @@ public function __construct() {
6565 add_filter ( 'wp_get_attachment_metadata ' , [ $ this , 'alter_attachment_metadata ' ], 10 , 2 );
6666 add_filter ( 'image_downsize ' , [ $ this , 'catch_downsize ' ], 10 , 3 );
6767 add_filter ( 'wp_prepare_attachment_for_js ' , [ $ this , 'alter_attachment_for_js ' ], 10 , 3 );
68- add_filter ( 'wp_image_src_get_dimensions ' , [ $ this , 'alter_img_tag_w_h ' ], 10 , 4 );
6968 add_filter ( 'get_attached_file ' , [ $ this , 'alter_attached_file_response ' ], 10 , 2 );
7069 add_filter ( 'wp_calculate_image_srcset ' , [ $ this , 'disable_dam_images_srcset ' ], 1 , 5 );
7170
@@ -204,16 +203,14 @@ public function alter_attachment_image_src( $image, $attachment_id, $size, $icon
204203 return $ image ;
205204 }
206205 $ image_url = wp_get_attachment_url ( $ attachment_id );
207- $ incoming_size = $ this ->parse_dimension_from_optimized_url ( $ image_url );
208- $ width = $ incoming_size [0 ];
209- $ height = $ incoming_size [1 ];
206+ list ($ width , $ height ) = $ this ->parse_dimension_from_optimized_url ( $ image_url );
210207
211208 // Skip resize in single attachment view on backend.
212209 if ( $ this ->is_attachment_edit_page ( $ attachment_id ) ) {
213210 return [
214211 $ image_url ,
215- $ width ,
216- $ height ,
212+ $ width === ' auto ' ? false : $ width ,
213+ $ height === ' auto ' ? false : $ height ,
217214 false ,
218215 ];
219216 }
@@ -657,53 +654,6 @@ public function alter_attachment_for_js( $response, $attachment, $meta ) {
657654 return $ response ;
658655 }
659656
660- /**
661- * We have to short-circuit the logic that adds width and height to the img tag.
662- * It compares the URL basename, and the `file` param for each image.
663- * This happens for any image that gets its size set non-explicitly
664- * e.g. an image block with its size set from the sidebar to `thumbnail`).
665- *
666- * Optimole has a single basename for all image resizes in its URL.
667- *
668- * @param array|false $dimensions Array with first element being the width
669- * and second element being the height, or
670- * false if dimensions could not be determined.
671- * @param string $image_src The image URL (will be Optimole URL).
672- * @param array $image_meta The image metadata.
673- * @param int $attachment_id The image attachment ID. Default 0.
674- */
675- public function alter_img_tag_w_h ( $ dimensions , $ image_src , $ image_meta , $ attachment_id ) {
676- if ( ! $ this ->is_dam_imported_image ( $ attachment_id ) ) {
677- return $ dimensions ;
678- }
679-
680- // Get the dimensions from the optimized URL.
681- $ incoming_size = $ this ->parse_dimension_from_optimized_url ( $ image_src );
682- $ width = $ incoming_size [0 ];
683- $ height = $ incoming_size [1 ];
684-
685- $ sizes = Optml_App_Replacer::image_sizes ();
686-
687- // If this is an image size. Return its dimensions.
688- foreach ( $ sizes as $ size => $ args ) {
689- if ( (int ) $ args ['width ' ] !== (int ) $ width ) {
690- continue ;
691- }
692-
693- if ( (int ) $ args ['height ' ] !== (int ) $ height ) {
694- continue ;
695- }
696-
697- return [
698- $ args ['width ' ],
699- $ args ['height ' ],
700- ];
701- }
702-
703- // Fall-through with the original dimensions.
704- return $ dimensions ;
705- }
706-
707657 /**
708658 * Replace the image size params in DAM URLs inside a string.
709659 *
0 commit comments