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:
Scott Taylor 2016-08-21 06:15:30 +00:00
parent 76540c6010
commit b8bfcb0d64
2 changed files with 6 additions and 6 deletions

View File

@ -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 );
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38295';
$wp_version = '4.7-alpha-38296';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.