#52196 closed defect (bug) (fixed)
wp_get_attachment_metadata() is broken if no first argument is passed in.
Reported by: | cfinke | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.6.1 | Priority: | normal |
Severity: | normal | Version: | 5.6 |
Component: | Media | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
In r49084 (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
.
It should be possible to keep the performance improvements for all cases where an attachment ID is passed in by only calling get_post()
when $attachment_id
is 0
. I'll upload a patch shortly.
Attachments (3)
Change History (15)
#1
@
4 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 5.6.1
Good catch @cfinke for this regression!
Moving this ticket into the next point release.
#3
@
4 years ago
As per doc @param int $attachment_id Attachment post ID. Defaults to global $post.
default value for $attachment_id is global $post
but in function use default value to 0.
https://github.com/WordPress/WordPress/blob/master/wp-includes/post.php#L6075
I think we have to change the doc block for that also? like
* @param int $attachment_id Attachment post ID. Default 0.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
4 years ago
#5
@
4 years ago
Hi, thanks for your help guys.
I am not sure the last doc update is not confusing.
Because if not attachment_id is passed, it equals to 0 yes, but then it fallbacks to global post with the modified patch, so it should stay like this IMO.
If no attachment ID is supplied, try to use the global $post's ID.