Make WordPress Core


Ignore:
Timestamp:
10/01/2020 05:53:38 PM (4 years ago)
Author:
helen
Message:

Media: Don't unnecessarily check for a valid attachment before getting meta.

This makes wp_get_attachment_metadata() run significantly faster. See ticket for benchmarking.

Props Tkama, donmhico.
Fixes #50679.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r49041 r49084  
    59935993    $attachment_id = (int) $attachment_id;
    59945994
    5995     $post = get_post( $attachment_id );
    5996     if ( ! $post ) {
     5995    $data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     5996
     5997    if ( empty( $data ) ) {
    59975998        return false;
    59985999    }
    5999 
    6000     $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
    60016000
    60026001    if ( $unfiltered ) {
     
    60136012     * @param int        $attachment_id Attachment post ID.
    60146013     */
    6015     return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
     6014    return apply_filters( 'wp_get_attachment_metadata', $data, $attachment_id );
    60166015}
    60176016
Note: See TracChangeset for help on using the changeset viewer.