Ticket #34477: 34477.1.patch
File 34477.1.patch, 3.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/media.php
814 814 // Generate 'srcset' and 'sizes' if not already present. 815 815 if ( empty( $attr['srcset'] ) ) { 816 816 $image_meta = wp_get_attachment_metadata( $attachment_id ); 817 $size_name = is_string( $size ) ? $size : ''; 817 818 818 819 if ( is_array( $image_meta ) ) { 819 820 $size_array = array( absint( $width ), absint( $height ) ); 820 821 $srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id ); 821 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );822 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $size_name ); 822 823 823 824 if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { 824 825 $attr['srcset'] = $srcset; … … 1082 1083 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. 1083 1084 * @param int $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed 1084 1085 * when using the image size name as argument for `$size`. 1085 * 1086 * @param string $size_name Optional. The image size name (thumbnail, medium, large, etc.). 1086 1087 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1087 1088 */ 1088 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0 ) {1089 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $size_name = '' ) { 1089 1090 $width = 0; 1090 1091 1091 1092 if ( is_numeric( $size ) ) { … … 1093 1094 } elseif ( is_array( $size ) ) { 1094 1095 $width = absint( $size[0] ); 1095 1096 } elseif ( is_string( $size ) ) { 1097 $size_name = $size; 1098 1096 1099 if ( ! $image_meta && $attachment_id ) { 1097 1100 $image_meta = wp_get_attachment_metadata( $attachment_id ); 1098 1101 } … … 1123 1126 * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. 1124 1127 * @param int $attachment_id Image attachment ID of the original image. 1125 1128 */ 1126 return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id );1129 return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $size_name ); 1127 1130 } 1128 1131 1129 1132 /** … … 1235 1238 return $image; 1236 1239 } 1237 1240 1241 $size_name = ''; 1242 1243 if ( strpos( $image, 'size-' ) !== false && preg_match( '/ class="([^"]+)"/', $image, $classes ) ) { 1244 $size_name = preg_match( '/(size-[^ ]+)/', $classes[1], $match_size_name ) ? $match_size_name[1] : ''; 1245 } 1246 1238 1247 $size_array = array( $width, $height ); 1239 1248 $srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id ); 1240 1249 1241 1250 if ( $srcset ) { 1242 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );1251 $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $size_name ); 1243 1252 } 1244 1253 1245 1254 if ( $srcset && $sizes ) {