After [35402], don't unnecessary run `wp_get_attachment_image_srcset()` and `wp_get_attachment_image_sizes()` in `wp_get_attachment_image()` if `srcset` is passed as an argument.

See #34379.

git-svn-id: https://develop.svn.wordpress.org/trunk@35404 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2015-10-26 18:40:01 +00:00
parent c1db6a9a56
commit aeca8fcfd8
1 changed files with 10 additions and 7 deletions

View File

@ -809,16 +809,19 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
if ( empty($default_attr['alt']) ) if ( empty($default_attr['alt']) )
$default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
$attr = wp_parse_args( $attr, $default_attr ); $attr = wp_parse_args( $attr, $default_attr );
$srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
$sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
// Generate srcset and sizes if not already present. // Generate srcset and sizes if not already present.
if ( empty( $attr['srcset'] ) && $srcset && $sizes ) { if ( empty( $attr['srcset'] ) ) {
$attr['srcset'] = $srcset; $srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
$sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
if ( empty( $attr['sizes'] ) ) { if ( $srcset && $sizes ) {
$attr['sizes'] = $sizes; $attr['srcset'] = $srcset;
if ( empty( $attr['sizes'] ) ) {
$attr['sizes'] = $sizes;
}
} }
} }