@@ -463,10 +463,10 @@ public function get_transformations_from_string( $str, $type = 'image' ) {
463463 * @return string Cloudinary URL.
464464 */
465465 public function attachment_url ( $ url , $ attachment_id ) {
466- if ( ! doing_action ( 'wp_insert_post_data ' ) && ! is_admin () ) {
466+ if ( ! doing_action ( 'wp_insert_post_data ' ) && false === $ this -> in_downsize ) {
467467 $ cloudinary_id = $ this ->cloudinary_id ( $ attachment_id );
468468 if ( false !== $ cloudinary_id ) {
469- $ url = $ this ->cloudinary_url ( $ attachment_id, $ cloudinary_id );
469+ $ url = $ this ->cloudinary_url ( $ attachment_id );
470470 }
471471 }
472472
@@ -722,10 +722,17 @@ public function filter_downsize( $image, $attachment_id, $size ) {
722722
723723 if ( false !== $ cloudinary_id ) {
724724 $ this ->in_downsize = true ;
725- $ image = image_downsize ( $ attachment_id , $ size );
725+ $ intermediate = image_get_intermediate_size ( $ attachment_id , $ size );
726+ if ( is_array ( $ intermediate ) ) {
727+ // Found an intermediate size.
728+ $ image = array (
729+ $ this ->convert_url ( $ intermediate ['url ' ], $ attachment_id , array (), false ),
730+ $ intermediate ['width ' ],
731+ $ intermediate ['height ' ],
732+ true ,
733+ );
734+ }
726735 $ this ->in_downsize = false ;
727-
728- $ image [0 ] = $ this ->convert_url ( $ image [0 ], $ attachment_id );
729736 }
730737
731738 return $ image ;
0 commit comments