Skip to content

Commit 7447e21

Browse files
committed
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. 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
1 parent a76f895 commit 7447e21

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/wp-includes/post.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6114,7 +6114,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
61146114
*
61156115
* @since 2.1.0
61166116
*
6117-
* @param int $attachment_id Attachment post ID. Defaults to global $post.
6117+
* @param int $attachment_id Attachment post ID. Default 0.
61186118
* @param bool $unfiltered Optional. If true, filters are not run. Default false.
61196119
* @return array|false {
61206120
* Attachment metadata. False on failure.
@@ -6130,6 +6130,16 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
61306130
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
61316131
$attachment_id = (int) $attachment_id;
61326132

6133+
if ( ! $attachment_id ) {
6134+
$post = get_post();
6135+
6136+
if ( ! $post ) {
6137+
return false;
6138+
}
6139+
6140+
$attachment_id = $post->ID;
6141+
}
6142+
61336143
$data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
61346144

61356145
if ( ! $data ) {

0 commit comments

Comments
 (0)