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
This commit is contained in:
Daryl Koopersmith 2012-09-06 09:50:41 +00:00
parent 2441d98446
commit 8763c79698

View File

@ -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(