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
|
@ -810,17 +810,20 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
|
||||||
$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 );
|
||||||
|
|
||||||
|
// Generate srcset and sizes if not already present.
|
||||||
|
if ( empty( $attr['srcset'] ) ) {
|
||||||
$srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
|
$srcset = wp_get_attachment_image_srcset( $attachment_id, $size );
|
||||||
$sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
|
$sizes = wp_get_attachment_image_sizes( $attachment_id, $size, $width );
|
||||||
|
|
||||||
// Generate srcset and sizes if not already present.
|
if ( $srcset && $sizes ) {
|
||||||
if ( empty( $attr['srcset'] ) && $srcset && $sizes ) {
|
|
||||||
$attr['srcset'] = $srcset;
|
$attr['srcset'] = $srcset;
|
||||||
|
|
||||||
if ( empty( $attr['sizes'] ) ) {
|
if ( empty( $attr['sizes'] ) ) {
|
||||||
$attr['sizes'] = $sizes;
|
$attr['sizes'] = $sizes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the list of attachment image attributes.
|
* Filter the list of attachment image attributes.
|
||||||
|
|
Loading…
Reference in New Issue