Add checks for attachment metadata when formatting attachments for JS.
Prevents notices from causing malformed ajax responses. see #21390. git-svn-id: https://develop.svn.wordpress.org/trunk@21772 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8085c5ac5a
commit
073cd101f5
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user