[wp-trac] [WordPress Trac] #50679: Optimization for wp_get_attachment_metadata()
WordPress Trac
noreply at wordpress.org
Thu Jul 16 11:33:30 UTC 2020
#50679: Optimization for wp_get_attachment_metadata()
-------------------------+-----------------------------
Reporter: Tkama | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.4.2
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
Link:
https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/#source
{{{#!php
function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered =
false ) {
$attachment_id = (int) $attachment_id;
$post = get_post( $attachment_id );
if ( ! $post ) {
return false;
}
$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true
);
if ( $unfiltered ) {
return $data;
}
/**
* Filters the attachment meta data.
*
* @since 2.1.0
*
* @param array|bool $data Array of meta data for the
given attachment, or false
* if the object does not exist.
* @param int $attachment_id Attachment post ID.
*/
return apply_filters( 'wp_get_attachment_metadata', $data,
$post->ID );
}
}}}
What this code for?
{{{#!php
$attachment_id = (int) $attachment_id;
$post = get_post( $attachment_id );
if ( ! $post ) {
return false;
}
}}}
Why we can't just pass `$attachment_id` to first parameter of
`get_post_meta()` and check result?
This no-needed code makes the function a little slower without any
advantages.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50679>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list