WordPress.org

Make WordPress Core

Changeset 50040 for branches/5.6


Ignore:
Timestamp:
01/28/2021 12:08:48 AM (9 months ago)
Author:
whyisjake
Message:

Media: Ensure that wp_get_attachment_metadata can return values from the global $post, if avaiable.

In [49084] (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.

This change restores that ability, while keeping the performance improvements from the original change.

This changeset brings [50039] to the 5.6 branch.

Fixes #52196.
Props cfinke, hellofromTonya, mukesh27, dilipbheda, Mista-Flo, audrasjb, SergeyBiryukov, whyisjake.

Location:
branches/5.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/src/wp-includes/post.php

    r49732 r50040  
    60726072 * @since 2.1.0
    60736073 *
    6074  * @param int  $attachment_id Attachment post ID. Defaults to global $post.
     6074 * @param int  $attachment_id Attachment post ID. Default 0.
    60756075 * @param bool $unfiltered    Optional. If true, filters are not run. Default false.
    60766076 * @return array|false {
     
    60876087function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    60886088    $attachment_id = (int) $attachment_id;
     6089
     6090    if ( ! $attachment_id ) {
     6091        $post = get_post();
     6092
     6093        if ( ! $post ) {
     6094            return false;
     6095        }
     6096
     6097        $attachment_id = $post->ID;
     6098    }
    60896099
    60906100    $data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
Note: See TracChangeset for help on using the changeset viewer.