From fec4b66f5bb5d8c60ca3dc0d813d13a9e7aa0a57 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 29 Mar 2013 20:51:35 +0000 Subject: [PATCH] Sanity checks on image metadata to avoid warnings, etc. fixes #23733. props wonderboymusic. git-svn-id: http://core.svn.wordpress.org/trunk@23873 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/custom-header.php | 4 ++-- wp-admin/includes/image-edit.php | 17 ++++++++++------- wp-admin/includes/media.php | 4 ++-- wp-includes/media.php | 20 ++++++++++++-------- wp-includes/theme.php | 6 ++++-- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index 7629af3d3a..12288430cd 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -663,8 +663,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> list( $width, $height, $type, $attr ) = getimagesize( $file ); } else { $data = wp_get_attachment_metadata( $attachment_id ); - $height = $data[ 'height' ]; - $width = $data[ 'width' ]; + $height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0; + $width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0; unset( $data ); } diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index b24d4f4a4c..22e209511c 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -13,7 +13,7 @@ function wp_image_editor($post_id, $msg = false) { $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']); $note = ''; - if ( is_array($meta) && isset($meta['width']) ) + if ( isset( $meta['width'], $meta['height'] ) ) $big = max( $meta['width'], $meta['height'] ); else die( __('Image data does not exist. Please re-upload the image.') ); @@ -21,8 +21,9 @@ function wp_image_editor($post_id, $msg = false) { $sizer = $big > 400 ? 400 / $big : 1; $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); - $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']) - && $backup_sizes['full-orig']['file'] != basename($meta['file']); + $can_restore = false; + if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) + $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] ); if ( $msg ) { if ( isset($msg->error) ) @@ -63,8 +64,8 @@ function wp_image_editor($post_id, $msg = false) { - - + +
@@ -82,9 +83,11 @@ function wp_image_editor($post_id, $msg = false) {

+

+
- × + × ! , 'scale')" class="button-primary" value="" />
@@ -499,7 +502,7 @@ function wp_restore_image($post_id) { $delpath = apply_filters('wp_delete_file', $file); @unlink($delpath); } - } else { + } elseif ( isset( $meta['width'], $meta['height'] ) ) { $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); } } diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 1d6d91a6b3..573c4db2ab 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -1127,7 +1127,7 @@ function get_media_item( $attachment_id, $args = null ) { $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); - if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) ) + if ( isset( $meta['width'], $meta['height'] ) ) $media_dims .= "{$meta['width']} × {$meta['height']} "; $media_dims = apply_filters( 'media_meta', $media_dims, $post ); @@ -2368,7 +2368,7 @@ function attachment_submitbox_metadata() { $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); - if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) ) + if ( isset( $meta['width'], $meta['height'] ) ) $media_dims .= "{$meta['width']} × {$meta['height']} "; $media_dims = apply_filters( 'media_meta', $media_dims, $post ); diff --git a/wp-includes/media.php b/wp-includes/media.php index 9ba8e295ec..ab2cf3e334 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -164,7 +164,7 @@ function image_downsize($id, $size = 'medium') { $is_intermediate = true; } } - if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { + if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { // any other type: use the real image $width = $meta['width']; $height = $meta['height']; @@ -780,7 +780,10 @@ function gallery_shortcode($attr) { foreach ( $attachments as $id => $attachment ) { $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $image_meta = wp_get_attachment_metadata( $id ); - $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; + + $orientation = ''; + if ( isset( $image_meta['height'], $image_meta['width'] ) ) + $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; $output .= "<{$itemtag} class='gallery-item'>"; $output .= " @@ -1626,12 +1629,13 @@ function wp_prepare_attachment_for_js( $attachment ) { } } - $sizes['full'] = array( - 'height' => $meta['height'], - 'width' => $meta['width'], - 'url' => $attachment_url, - 'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape', - ); + $sizes['full'] = array( 'url' => $attachment_url ); + + if ( isset( $meta['height'], $meta['width'] ) ) { + $sizes['full']['height'] = $meta['height']; + $sizes['full']['width'] = $meta['width']; + $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; + } $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); } diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 8b8f42c8fc..2150b46ecd 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1013,8 +1013,10 @@ function get_uploaded_header_images() { $header_images[$header_index]['attachment_id'] = $header->ID; $header_images[$header_index]['url'] = $url; $header_images[$header_index]['thumbnail_url'] = $url; - $header_images[$header_index]['width'] = $header_data['width']; - $header_images[$header_index]['height'] = $header_data['height']; + if ( isset( $header_data['width'] ) ) + $header_images[$header_index]['width'] = $header_data['width']; + if ( isset( $header_data['height'] ) ) + $header_images[$header_index]['height'] = $header_data['height']; } return $header_images;