[wp-trac] [WordPress Trac] #52389: Consistently check for non-empty post ID in attachment functions
WordPress Trac
noreply at wordpress.org
Thu Jan 28 10:53:31 UTC 2021
#52389: Consistently check for non-empty post ID in attachment functions
-------------------------------+--------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.7
Component: Posts, Post Types | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------------+--------------------
Background: #50679, #52196.
As a result of the changes in [49084] and [50039],
`wp_get_attachment_metadata()` conditionally calls `get_post()` if the
attachment ID is not passed:
{{{
$attachment_id = (int) $attachment_id;
if ( ! $attachment_id ) {
$post = get_post();
if ( ! $post ) {
return false;
}
$attachment_id = $post->ID;
}
}}}
This is not really consistent with other attachment functions, which just
always call `get_post()` unconditionally:
{{{
$attachment_id = (int) $attachment_id;
$post = get_post( $attachment_id );
}}}
Let's bring some consistency here, there is no reason for these minor
differences.
This applies at least to:
* `wp_get_attachment_metadata()`
* `wp_get_attachment_url()`
* `wp_get_attachment_caption()`
* `wp_get_attachment_thumb_file()`
* `wp_get_attachment_thumb_url()`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/52389>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list