Changeset 35405
- Timestamp:
- 10/26/2015 06:41:31 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r35404 r35405 1146 1146 $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : false; 1147 1147 1148 if ( $id && false ===$size ) {1148 if ( $id && ! $size ) { 1149 1149 $height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : false; 1150 1150 … … 1153 1153 } 1154 1154 } 1155 1156 $meta = wp_get_attachment_metadata( $id );1157 1155 1158 1156 /* … … 1160 1158 * metadata to match the 'src' against the available sizes for an attachment. 1161 1159 */ 1162 if ( ! $size && ! empty( $id ) && is_array( $meta ) ) { 1160 if ( $id && ! $size ) { 1161 $meta = wp_get_attachment_metadata( $id ); 1162 1163 1163 // Parse the image src value from the img element. 1164 1164 $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false; 1165 1165 1166 // Return early if the src value is empty.1167 if ( ! $ src ) {1166 // Return early if the metadata does not exist or the src value is empty. 1167 if ( ! $meta || ! $src ) { 1168 1168 return $image; 1169 1169 } … … 1188 1188 } 1189 1189 1190 $srcset = wp_get_attachment_image_srcset( $id, $size );1191 $sizes = wp_get_attachment_image_sizes( $id, $size, $width );1192 1193 1190 // If ID and size exist, try for 'srcset' and 'sizes' and update the markup. 1194 if ( $id && $size && $srcset && $sizes ) { 1195 // Format the srcset and sizes string and escape attributes. 1196 $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) ); 1197 1198 // Add srcset and sizes attributes to the image markup. 1199 $image = preg_replace( '/<img ([^>]+)[\s?][\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image ); 1191 if ( $id && $size ) { 1192 $srcset = wp_get_attachment_image_srcset( $id, $size ); 1193 $sizes = wp_get_attachment_image_sizes( $id, $size, $width ); 1194 1195 if ( $srcset && $sizes ) { 1196 // Format the srcset and sizes string and escape attributes. 1197 $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) ); 1198 1199 // Add srcset and sizes attributes to the image markup. 1200 $image = preg_replace( '/<img ([^>]+)[\s?][\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image ); 1201 } 1200 1202 } 1201 1203
Note: See TracChangeset
for help on using the changeset viewer.