From 2fd45b514b03a5777640431bf616cc860e7df02d Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Thu, 24 Jul 2014 18:03:58 +0000 Subject: [PATCH] Set default values for attachment meta and ID3 data when preparing for JS to avoid errors in rendering templates. props ericmann for the initial patch. fixes #29013. git-svn-id: https://develop.svn.wordpress.org/trunk@29281 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media-template.php | 2 +- src/wp-includes/media.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index c679cc011b..c3f78d780c 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -325,7 +325,7 @@ function wp_print_media_templates() {
{{ data.fileLength }}
<# } #> - <# if ( 'audio' === data.type && data.meta && data.meta.bitrate ) { #> + <# if ( 'audio' === data.type && data.meta.bitrate ) { #>
{{ Math.round( data.meta.bitrate / 1000 ) }}kb/s <# if ( data.meta.bitrate_mode ) { #> diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index cd32ae1c6c..b4f24e6cf0 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2628,6 +2628,7 @@ function wp_prepare_attachment_for_js( $attachment ) { 'edit' => false ), 'editLink' => false, + 'meta' => false, ); $author = new WP_User( $attachment->post_author ); @@ -2725,6 +2726,8 @@ function wp_prepare_attachment_for_js( $attachment ) { $response['meta'] = array(); foreach ( wp_get_attachment_id3_keys( $attachment, 'js' ) as $key => $label ) { + $response['meta'][ $key ] = false; + if ( ! empty( $meta[ $key ] ) ) { $response['meta'][ $key ] = $meta[ $key ]; }