@@ -1032,6 +1032,10 @@ public function convert_tags( $content, $context = 'view' ) {
10321032 $ replacements = array_merge ( $ replacements , $ aliases );
10331033 }
10341034
1035+ // Sort by length, so we replace the longest first and prevent early replacements.
1036+ $ keys = array_map ( 'strlen ' , array_keys ( $ replacements ) );
1037+ array_multisort ( $ keys , SORT_DESC , $ replacements );
1038+
10351039 // Update the post meta cache.
10361040 if ( is_singular () ) {
10371041 $ has_cache = array ();
@@ -1140,7 +1144,7 @@ protected function standardize_tag( $tag_element ) {
11401144 $ local_size = filesize ( get_attached_file ( $ tag_element ['id ' ] ) );
11411145 }
11421146 $ remote_size = get_post_meta ( $ tag_element ['id ' ], Sync::META_KEYS ['remote_size ' ], true );
1143- $ tag_element ['atts ' ]['data-filesize ' ] = size_format ( $ local_size );
1147+ $ tag_element ['atts ' ]['data-filesize ' ] = size_format ( $ local_size );
11441148 $ tag_element ['atts ' ]['data-optsize ' ] = size_format ( $ remote_size );
11451149 $ tag_element ['atts ' ]['data-optformat ' ] = get_post_meta ( $ tag_element ['id ' ], Sync::META_KEYS ['remote_format ' ], true );
11461150 if ( ! empty ( $ local_size ) && ! empty ( $ remote_size ) ) {
@@ -1154,6 +1158,29 @@ protected function standardize_tag( $tag_element ) {
11541158
11551159 $ tag_element ['atts ' ]['data-version ' ] = $ this ->media ->get_cloudinary_version ( $ tag_element ['id ' ] );
11561160
1161+ /**
1162+ * Bypass Cloudinary's SEO URLs.
1163+ *
1164+ * @hook cloudinary_bypass_seo_url
1165+ * @since 3.1.5
1166+ *
1167+ * @param $bypass_seo_url {bool} Whether to bypass SEO URLs.
1168+ *
1169+ * @return {bool}
1170+ */
1171+ $ bypass_seo_url = apply_filters ( 'cloudinary_bypass_seo_url ' , false );
1172+
1173+ $ tag_element ['atts ' ]['data-seo ' ] = ! $ bypass_seo_url ;
1174+
1175+ $ resource_type = in_array ( $ tag_element ['type ' ], array ( 'image ' , 'video ' ), true ) ? $ tag_element ['type ' ] : 'raw ' ;
1176+
1177+ $ args = array (
1178+ 'delivery ' => $ this ->media ->get_media_delivery ( $ tag_element ['id ' ] ),
1179+ 'resource_type ' => $ resource_type ,
1180+ );
1181+
1182+ $ tag_element ['atts ' ]['data-public-id ' ] = $ this ->plugin ->get_component ( 'connect ' )->api ->get_public_id ( $ tag_element ['id ' ], '' , $ args );
1183+
11571184 return $ tag_element ;
11581185 }
11591186
@@ -1182,9 +1209,10 @@ public function rebuild_tag( $tag_element ) {
11821209 if ( apply_filters ( 'cloudinary_apply_breakpoints ' , true ) ) {
11831210 $ meta = wp_get_attachment_metadata ( $ tag_element ['id ' ] );
11841211 if ( ! empty ( $ meta ['width ' ] ) && ! empty ( $ meta ['height ' ] ) ) {
1212+ $ relationship = Relationship::get_relationship ( $ tag_element ['id ' ] );
11851213 // Check overwrite.
11861214 $ meta ['overwrite_transformations ' ] = $ tag_element ['overwrite_transformations ' ];
1187- $ meta ['cloudinary_id ' ] = $ tag_element [ ' atts ' ][ ' data-public-id ' ] ;
1215+ $ meta ['cloudinary_id ' ] = $ relationship -> public_id ;
11881216 $ meta ['transformations ' ] = $ tag_element ['transformations ' ];
11891217 // Add new srcset.
11901218 $ element = wp_image_add_srcset_and_sizes ( $ tag_element ['original ' ], $ meta , $ tag_element ['id ' ] );
@@ -1318,7 +1346,7 @@ public function parse_element( $element ) {
13181346 $ tag_element ['height ' ] = ! empty ( $ attributes ['height ' ] ) ? $ attributes ['height ' ] : $ item ['height ' ];
13191347 $ attributes ['data-public-id ' ] = $ public_id ;
13201348 $ tag_element ['format ' ] = $ item ['format ' ];
1321-
1349+
13221350 if ( 'img ' === $ tag_element ['tag ' ] ) {
13231351 // Check if this is a crop or a scale.
13241352 $ has_size = $ this ->media ->get_size_from_url ( $ this ->sanitize_url ( $ raw_url ) );
0 commit comments