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:
parent
c1db6a9a56
commit
aeca8fcfd8
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue