@@ -64,6 +64,7 @@ public function convert_cloudinary_version( $attachment_id ) {
6464 $ asset_version = 1 ;
6565 $ asset_transformations = array ();
6666 $ id_parts = array ();
67+ $ public_id = $ this ->get_fetch_public_id ( $ path , $ attachment_id );
6768 foreach ( $ parts as $ val ) {
6869 if ( empty ( $ val ) ) {
6970 continue ;
@@ -73,7 +74,7 @@ public function convert_cloudinary_version( $attachment_id ) {
7374 $ cloud_name = md5 ( $ val );
7475 continue ;
7576 }
76- if ( in_array ( $ val , array ( 'images ' , 'image ' , 'video ' , 'upload ' ), true ) ) {
77+ if ( in_array ( $ val , array ( 'images ' , 'image ' , 'video ' , 'upload ' , ' fetch ' ), true ) ) {
7778 continue ;
7879 }
7980 $ transformation_maybe = $ media ->get_transformations_from_string ( $ val );
@@ -93,11 +94,10 @@ public function convert_cloudinary_version( $attachment_id ) {
9394 }
9495 }
9596 // Build public_id.
96- $ parts = array_filter ( $ id_parts );
97- $ public_id = implode ( '/ ' , $ parts );
98- // Remove extension.
99- $ path = pathinfo ( $ public_id );
100- $ public_id = str_replace ( $ path ['basename ' ], $ path ['filename ' ], $ public_id );
97+ $ parts = array_filter ( $ id_parts );
98+ if ( empty ( $ public_id ) ) {
99+ $ public_id = implode ( '/ ' , $ parts );
100+ }
101101 update_post_meta ( $ attachment_id , Sync::META_KEYS ['public_id ' ], $ public_id );
102102 $ this ->media ->update_post_meta ( $ attachment_id , Sync::META_KEYS ['version ' ], $ asset_version );
103103 if ( ! empty ( $ asset_transformations ) ) {
@@ -140,6 +140,25 @@ public function convert_cloudinary_version( $attachment_id ) {
140140 return $ public_id ;
141141 }
142142
143+ /**
144+ * Maybe the upgraded attachment is a fetch image.
145+ *
146+ * @param string $path The attachment path.
147+ * @param int $attachment_id The attachment ID.
148+ *
149+ * @return string
150+ */
151+ public function get_fetch_public_id ( $ path , $ attachment_id ) {
152+ $ parts = explode ( '/image/fetch/ ' , $ path );
153+
154+ if ( ! empty ( $ parts [1 ] ) ) {
155+ $ this ->media ->update_post_meta ( $ attachment_id , Sync::META_KEYS ['delivery ' ], 'fetch ' );
156+ return $ parts [1 ];
157+ }
158+
159+ return '' ;
160+ }
161+
143162 /**
144163 * Setup hooks for the filters.
145164 */
0 commit comments