Changeset 35569 for trunk/src/wp-includes/media.php
- Timestamp:
- 11/07/2015 09:35:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r35567 r35569 827 827 if ( is_array( $image_meta ) ) { 828 828 $size_array = array( absint( $width ), absint( $height ) ); 829 $srcset = wp_calculate_image_srcset( $s rc, $size_array, $image_meta, $attachment_id );830 $sizes = wp_ get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src);829 $srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id ); 830 $sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id ); 831 831 832 832 if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { … … 934 934 * 935 935 * @param int $attachment_id Image attachment ID. 936 * @param array|string $size Image size. Accepts any valid image size, or an array of width and height937 * values in pixels (in that order). Default 'medium'.936 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of 937 * width and height values in pixels (in that order). Default 'medium'. 938 938 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. 939 939 * @return string|bool A 'srcset' value string or false. … … 954 954 ); 955 955 956 return wp_calculate_image_srcset( $ image_src, $size_array, $image_meta, $attachment_id );956 return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); 957 957 } 958 958 … … 962 962 * @since 4.4.0 963 963 * 964 * @param array $size_array Array of width and height values in pixels (in that order). 964 965 * @param string $image_src The 'src' of the image. 965 * @param array $size_array Array of width and height values in pixels (in that order).966 966 * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. 967 967 * @param int $attachment_id Optional. The image attachment ID to pass to the filter. 968 968 * @return string|bool The 'srcset' attribute value. False on error or when only one source exists. 969 969 */ 970 function wp_calculate_image_srcset( $ image_src, $size_array, $image_meta, $attachment_id = 0 ) {970 function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) { 971 971 if ( empty( $image_meta['sizes'] ) ) { 972 972 return false; … … 1107 1107 1108 1108 /** 1109 * Retrieves the value for an image attachment's 'sizes' attribute. 1110 * 1111 * @since 4.4.0 1112 * 1113 * @param int $attachment_id Image attachment ID. 1114 * @param array|string $size Optional. Image size. Accepts any valid image size, or an array of width 1115 * and height values in pixels (in that order). Default 'medium'. 1116 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. 1117 * @return string|bool A 'srcset' value string or false. 1118 */ 1119 function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { 1120 if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { 1121 return false; 1122 } 1123 1124 if ( ! is_array( $image_meta ) ) { 1125 $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); 1126 } 1127 1128 $image_src = $image[0]; 1129 $size_array = array( 1130 absint( $image[1] ), 1131 absint( $image[2] ) 1132 ); 1133 1134 return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); 1135 } 1136 1137 /** 1109 1138 * Create 'sizes' attribute value for an image. 1110 1139 * 1111 1140 * @since 4.4.0 1112 1141 * 1113 * @param array|string $size Image size . Accepts any valid image size name ('thumbnail', 'medium', etc.),1114 * o r an array of width and height values in pixels (in that order).1142 * @param array|string $size Image size to retrieve. Accepts any valid image size, or an array 1143 * of width and height values in pixels (in that order). Default 'medium'. 1115 1144 * @param array $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'. 1116 1145 * @param int $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed … … 1120 1149 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1121 1150 */ 1122 function wp_ get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_src = null) {1151 function wp_calculate_image_sizes( $size, $image_src, $image_meta, $attachment_id = 0 ) { 1123 1152 $width = 0; 1124 1153 … … 1146 1175 1147 1176 /** 1148 * Filter the output of 'wp_ get_attachment_image_sizes()'.1177 * Filter the output of 'wp_calculate_image_sizes()'. 1149 1178 * 1150 1179 * @since 4.4.0 1151 1180 * 1152 1181 * @param string $sizes A source size value for use in a 'sizes' attribute. 1153 * @param array|string $size Image size. Image size name, or an array of width and height 1154 * values in pixels (in that order). 1182 * @param array|string $size Requested size. Image size or array of width and height values 1183 * in pixels (in that order). Default 'medium'. 1184 * @param string $image_src The URL to the image file. 1155 1185 * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. 1156 1186 * @param int $attachment_id Image attachment ID of the original image. 1157 * @param string $image_src Optional. The URL to the image file. 1158 */ 1159 return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $image_src ); 1187 */ 1188 return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id ); 1160 1189 } 1161 1190 … … 1226 1255 } 1227 1256 1228 $ src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';1229 list( $ src ) = explode( '?', $src );1257 $image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : ''; 1258 list( $image_src ) = explode( '?', $image_src ); 1230 1259 1231 1260 // Return early if we couldn't get the image source. 1232 if ( ! $ src ) {1261 if ( ! $image_src ) { 1233 1262 return $image; 1234 1263 } … … 1236 1265 // Bail early if an image has been inserted and later edited. 1237 1266 if ( preg_match( '/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash ) && 1238 strpos( wp_basename( $ src ), $img_edit_hash[0] ) === false ) {1267 strpos( wp_basename( $image_src ), $img_edit_hash[0] ) === false ) { 1239 1268 1240 1269 return $image; … … 1249 1278 * the image file name from 'src' against the available sizes for an attachment. 1250 1279 */ 1251 $image_filename = wp_basename( $ src );1280 $image_filename = wp_basename( $image_src ); 1252 1281 1253 1282 if ( $image_filename === wp_basename( $image_meta['file'] ) ) { … … 1270 1299 1271 1300 $size_array = array( $width, $height ); 1272 $srcset = wp_calculate_image_srcset( $s rc, $size_array, $image_meta, $attachment_id );1301 $srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); 1273 1302 1274 1303 if ( $srcset ) { 1275 $sizes = wp_ get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $src);1304 $sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); 1276 1305 } 1277 1306
Note: See TracChangeset
for help on using the changeset viewer.