Media: use wp_get_attachment_metadata() instead of get_post_meta() where appropriate.
Adds unit test. Props JorritSchippers. Fixes #36246. Built from https://develop.svn.wordpress.org/trunk@38296 git-svn-id: http://core.svn.wordpress.org/trunk@38237 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -861,7 +861,7 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
|
||||
|
||||
// Generate 'srcset' and 'sizes' if not already present.
|
||||
if ( empty( $attr['srcset'] ) ) {
|
||||
$image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
||||
$image_meta = wp_get_attachment_metadata( $attachment_id );
|
||||
|
||||
if ( is_array( $image_meta ) ) {
|
||||
$size_array = array( absint( $width ), absint( $height ) );
|
||||
@@ -990,7 +990,7 @@ function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $imag
|
||||
}
|
||||
|
||||
if ( ! is_array( $image_meta ) ) {
|
||||
$image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
||||
$image_meta = wp_get_attachment_metadata( $attachment_id );
|
||||
}
|
||||
|
||||
$image_src = $image[0];
|
||||
@@ -1206,7 +1206,7 @@ function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image
|
||||
}
|
||||
|
||||
if ( ! is_array( $image_meta ) ) {
|
||||
$image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
||||
$image_meta = wp_get_attachment_metadata( $attachment_id );
|
||||
}
|
||||
|
||||
$image_src = $image[0];
|
||||
@@ -1239,7 +1239,7 @@ function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null,
|
||||
$width = absint( $size[0] );
|
||||
} elseif ( is_string( $size ) ) {
|
||||
if ( ! $image_meta && $attachment_id ) {
|
||||
$image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
||||
$image_meta = wp_get_attachment_metadata( $attachment_id );
|
||||
}
|
||||
|
||||
if ( is_array( $image_meta ) ) {
|
||||
@@ -1314,7 +1314,7 @@ function wp_make_content_images_responsive( $content ) {
|
||||
}
|
||||
|
||||
foreach ( $selected_images as $image => $attachment_id ) {
|
||||
$image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
||||
$image_meta = wp_get_attachment_metadata( $attachment_id );
|
||||
$content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user