Changeset 35402
- Timestamp:
- 10/26/2015 04:28:27 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r35401 r35402 810 810 $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title 811 811 812 $attr = wp_parse_args($attr, $default_attr); 812 $attr = wp_parse_args( $attr, $default_attr ); 813 $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ); 814 $sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width ); 813 815 814 816 // Generate srcset and sizes if not already present. 815 if ( empty( $attr['srcset'] ) && ( $srcset = wp_get_attachment_image_srcset( $attachment_id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width ) )) {817 if ( empty( $attr['srcset'] ) && $srcset && $sizes ) { 816 818 $attr['srcset'] = $srcset; 817 819 … … 1149 1151 } 1150 1152 1153 $meta = wp_get_attachment_metadata( $id ); 1154 1151 1155 /* 1152 1156 * If attempts to parse the size value failed, attempt to use the image 1153 1157 * metadata to match the 'src' against the available sizes for an attachment. 1154 1158 */ 1155 if ( ! $size && ! empty( $id ) && is_array( $meta = wp_get_attachment_metadata( $id )) ) {1159 if ( ! $size && ! empty( $id ) && is_array( $meta ) ) { 1156 1160 // Parse the image src value from the img element. 1157 1161 $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false; … … 1181 1185 } 1182 1186 1187 $srcset = wp_get_attachment_image_srcset( $id, $size ); 1188 $sizes = wp_get_attachment_image_sizes( $id, $size, $width ); 1189 1183 1190 // If ID and size exist, try for 'srcset' and 'sizes' and update the markup. 1184 if ( $id && $size && ( $srcset = wp_get_attachment_image_srcset( $id, $size ) ) && ( $sizes = wp_get_attachment_image_sizes( $id, $size, $width ) )) {1191 if ( $id && $size && $srcset && $sizes ) { 1185 1192 // Format the srcset and sizes string and escape attributes. 1186 1193 $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) );
Note: See TracChangeset
for help on using the changeset viewer.