Media: Ensure that wp_get_attachment_metadata can return values from the global $post, if avaiable.

In [49084] (for #50679), wp_get_attachment_metadata() was changed to improve performance, but it had the side effect of eliminating the ability to call it with no arguments and have it default to using the global $post.

This change restores that ability, while keeping the performance improvements from the original change.

This changeset brings [50039] to the 5.6 branch.

Fixes #52196.
Props cfinke, hellofromTonya, mukesh27, dilipbheda, Mista-Flo, audrasjb, SergeyBiryukov, whyisjake.

Built from https://develop.svn.wordpress.org/branches/5.6@50040


git-svn-id: http://core.svn.wordpress.org/branches/5.6@49741 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2021-01-28 00:09:57 +00:00
parent afeec1960d
commit 126a488b6f
2 changed files with 12 additions and 2 deletions

View File

@ -6071,7 +6071,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param int $attachment_id Attachment post ID. Defaults to global $post. * @param int $attachment_id Attachment post ID. Default 0.
* @param bool $unfiltered Optional. If true, filters are not run. Default false. * @param bool $unfiltered Optional. If true, filters are not run. Default false.
* @return array|false { * @return array|false {
* Attachment metadata. False on failure. * Attachment metadata. False on failure.
@ -6087,6 +6087,16 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
$attachment_id = (int) $attachment_id; $attachment_id = (int) $attachment_id;
if ( ! $attachment_id ) {
$post = get_post();
if ( ! $post ) {
return false;
}
$attachment_id = $post->ID;
}
$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true ); $data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
if ( ! $data ) { if ( ! $data ) {

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6.1-alpha-50038'; $wp_version = '5.6.1-alpha-50040';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.