From 4803207ba1a668250914543de2f4552e26bebb5c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 15 Jun 2021 16:52:56 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@51162 git-svn-id: http://core.svn.wordpress.org/trunk@50771 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/image.php | 12 ++++++++---- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index b3b68560b4..5580ee5978 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -470,7 +470,7 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) { * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. - * @return mixed Metadata for attachment. + * @return array Metadata for attachment. */ function wp_generate_attachment_metadata( $attachment_id, $file ) { $attachment = get_post( $attachment_id ); @@ -490,6 +490,12 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' ); } + // wp_read_video_metadata() and wp_read_audio_metadata() return `false` if the attachment + // does not exist in the local filesystem, so make sure to convert the value to an array. + if ( ! is_array( $metadata ) ) { + $metadata = array(); + } + if ( $support && ! empty( $metadata['image']['data'] ) ) { // Check for existing cover. $hash = md5( $metadata['image']['data'] ); @@ -616,9 +622,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { } // Remove the blob of binary data from the array. - if ( $metadata ) { - unset( $metadata['image']['data'] ); - } + unset( $metadata['image']['data'] ); /** * Filters the generated attachment meta data. diff --git a/wp-includes/version.php b/wp-includes/version.php index 4e91deec80..1c7f406487 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-beta1-51161'; +$wp_version = '5.8-beta1-51162'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.