Skip to content

Commit

Permalink
Media: Ensure that wp_get_attachment_metadata can return values fro…
Browse files Browse the repository at this point in the history
…m 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.

Fixes #52196.

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



git-svn-id: https://develop.svn.wordpress.org/trunk@50039 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
whyisjake committed Jan 28, 2021
1 parent a76f895 commit 7447e21
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6114,7 +6114,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
*
* @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.
* @return array|false {
* Attachment metadata. False on failure.
Expand All @@ -6130,6 +6130,16 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
$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 );

if ( ! $data ) {
Expand Down

0 comments on commit 7447e21

Please sign in to comment.