From 8763c7969847865147ff942a86c0f5e5f71e4dac Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Thu, 6 Sep 2012 09:50:41 +0000 Subject: [PATCH] Add checks for attachment metadata when formatting attachments for JS. Prevents notices from causing malformed ajax responses. see #21390. git-svn-id: http://core.svn.wordpress.org/trunk@21772 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index a23e02c96d..7f735577c9 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1571,17 +1571,19 @@ function wp_prepare_attachment_for_js( $attachment ) { 'subtype' => $subtype, ); - if ( 'image' === $type ) { + if ( $meta && 'image' === $type ) { $sizes = array(); $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); - foreach ( $meta['sizes'] as $slug => $size ) { - $sizes[ $slug ] = array( - 'height' => $size['height'], - 'width' => $size['width'], - 'url' => $base_url . $size['file'], - 'orientation' => $size['height'] > $size['width'] ? 'portrait' : 'landscape', - ); + if ( isset( $meta['sizes'] ) ) { + foreach ( $meta['sizes'] as $slug => $size ) { + $sizes[ $slug ] = array( + 'height' => $size['height'], + 'width' => $size['width'], + 'url' => $base_url . $size['file'], + 'orientation' => $size['height'] > $size['width'] ? 'portrait' : 'landscape', + ); + } } $response = array_merge( $response, array(