Make WordPress Core

Changeset 51162


Ignore:
Timestamp:
06/15/2021 04:51:54 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Media: Make sure wp_generate_attachment_metadata() always returns an array.

This matches the documentation for the filter of the same name.

Previously, the function could return false for an audio or video attachment that does not exist in the local filesystem.

Props Chouby, SergeyBiryukov.
Fixes #52603.

File:
1 edited

Legend:

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

    r50815 r51162  
    471471 * @param int    $attachment_id Attachment Id to process.
    472472 * @param string $file          Filepath of the Attached image.
    473  * @return mixed Metadata for attachment.
     473 * @return array Metadata for attachment.
    474474 */
    475475function wp_generate_attachment_metadata( $attachment_id, $file ) {
     
    489489        $metadata = wp_read_audio_metadata( $file );
    490490        $support  = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
     491    }
     492
     493    // wp_read_video_metadata() and wp_read_audio_metadata() return `false` if the attachment
     494    // does not exist in the local filesystem, so make sure to convert the value to an array.
     495    if ( ! is_array( $metadata ) ) {
     496        $metadata = array();
    491497    }
    492498
     
    617623
    618624    // Remove the blob of binary data from the array.
    619     if ( $metadata ) {
    620         unset( $metadata['image']['data'] );
    621     }
     625    unset( $metadata['image']['data'] );
    622626
    623627    /**
Note: See TracChangeset for help on using the changeset viewer.