WordPress.org

Make WordPress Core

Ticket #52196: 52196.diff

File 52196.diff, 570 bytes (added by cfinke, 6 months ago)

If no attachment ID is supplied, try to use the global $post's ID.

  • src/wp-includes/post.php

     
    60886088function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    60896089        $attachment_id = (int) $attachment_id;
    60906090
     6091        if ( ! $attachment_id ) {
     6092                $post = get_post();
     6093
     6094                if ( ! $post ) {
     6095                        return false;
     6096                }
     6097
     6098                $attachment_id = $post->ID;
     6099        }
     6100
    60916101        $data = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
    60926102
    60936103        if ( ! $data ) {