WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/21/2016 06:14:37 AM (3 years ago)
Author:
wonderboymusic
Message:

Media: use wp_get_attachment_metadata() instead of get_post_meta() where appropriate.

Adds unit test.

Props JorritSchippers.
Fixes #36246.

File:
1 edited

Legend:

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

    r38292 r38296  
    862862        // Generate 'srcset' and 'sizes' if not already present.
    863863        if ( empty( $attr['srcset'] ) ) {
    864             $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     864            $image_meta = wp_get_attachment_metadata( $attachment_id );
    865865
    866866            if ( is_array( $image_meta ) ) {
     
    991991
    992992    if ( ! is_array( $image_meta ) ) {
    993         $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     993        $image_meta = wp_get_attachment_metadata( $attachment_id );
    994994    }
    995995
     
    12071207
    12081208    if ( ! is_array( $image_meta ) ) {
    1209         $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     1209        $image_meta = wp_get_attachment_metadata( $attachment_id );
    12101210    }
    12111211
     
    12401240    } elseif ( is_string( $size ) ) {
    12411241        if ( ! $image_meta && $attachment_id ) {
    1242             $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     1242            $image_meta = wp_get_attachment_metadata( $attachment_id );
    12431243        }
    12441244
     
    13151315
    13161316    foreach ( $selected_images as $image => $attachment_id ) {
    1317         $image_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
     1317        $image_meta = wp_get_attachment_metadata( $attachment_id );
    13181318        $content = str_replace( $image, wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ), $content );
    13191319    }
Note: See TracChangeset for help on using the changeset viewer.