<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[23873] trunk: Sanity checks on image metadata to avoid warnings, etc.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/23873">23873</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-03-29 20:51:35 +0000 (Fri, 29 Mar 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Sanity checks on image metadata to avoid warnings, etc.

fixes <a href="http://core.trac.wordpress.org/ticket/23733">#23733</a>. props wonderboymusic.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustomheaderphp">trunk/wp-admin/custom-header.php</a></li>
<li><a href="#trunkwpadminincludesimageeditphp">trunk/wp-admin/includes/image-edit.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustomheaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-header.php (23872 => 23873)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-header.php        2013-03-29 20:50:09 UTC (rev 23872)
+++ trunk/wp-admin/custom-header.php        2013-03-29 20:51:35 UTC (rev 23873)
</span><span class="lines">@@ -663,8 +663,8 @@
</span><span class="cx">                         list( $width, $height, $type, $attr ) = getimagesize( $file );
</span><span class="cx">                 } else {
</span><span class="cx">                         $data = wp_get_attachment_metadata( $attachment_id );
</span><del>-                        $height = $data[ 'height' ];
-                        $width = $data[ 'width' ];
</del><ins>+                        $height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
+                        $width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
</ins><span class="cx">                         unset( $data );
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesimageeditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image-edit.php (23872 => 23873)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image-edit.php        2013-03-29 20:50:09 UTC (rev 23872)
+++ trunk/wp-admin/includes/image-edit.php        2013-03-29 20:51:35 UTC (rev 23873)
</span><span class="lines">@@ -13,7 +13,7 @@
</span><span class="cx">         $sub_sizes = isset($meta['sizes']) &amp;&amp; is_array($meta['sizes']);
</span><span class="cx">         $note = '';
</span><span class="cx"> 
</span><del>-        if ( is_array($meta) &amp;&amp; isset($meta['width']) )
</del><ins>+        if ( isset( $meta['width'], $meta['height'] ) )
</ins><span class="cx">                 $big = max( $meta['width'], $meta['height'] );
</span><span class="cx">         else
</span><span class="cx">                 die( __('Image data does not exist. Please re-upload the image.') );
</span><span class="lines">@@ -21,8 +21,9 @@
</span><span class="cx">         $sizer = $big &gt; 400 ? 400 / $big : 1;
</span><span class="cx"> 
</span><span class="cx">         $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
</span><del>-        $can_restore = !empty($backup_sizes) &amp;&amp; isset($backup_sizes['full-orig'])
-                &amp;&amp; $backup_sizes['full-orig']['file'] != basename($meta['file']);
</del><ins>+        $can_restore = false;
+        if ( ! empty( $backup_sizes ) &amp;&amp; isset( $backup_sizes['full-orig'], $meta['file'] ) )
+                $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] );
</ins><span class="cx"> 
</span><span class="cx">         if ( $msg ) {
</span><span class="cx">                 if ( isset($msg-&gt;error) )
</span><span class="lines">@@ -63,8 +64,8 @@
</span><span class="cx">         &lt;input type=&quot;hidden&quot; id=&quot;imgedit-history-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&quot; /&gt;
</span><span class="cx">         &lt;input type=&quot;hidden&quot; id=&quot;imgedit-undone-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;0&quot; /&gt;
</span><span class="cx">         &lt;input type=&quot;hidden&quot; id=&quot;imgedit-selection-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&quot; /&gt;
</span><del>-        &lt;input type=&quot;hidden&quot; id=&quot;imgedit-x-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&lt;?php echo $meta['width']; ?&gt;&quot; /&gt;
-        &lt;input type=&quot;hidden&quot; id=&quot;imgedit-y-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&lt;?php echo $meta['height']; ?&gt;&quot; /&gt;
</del><ins>+        &lt;input type=&quot;hidden&quot; id=&quot;imgedit-x-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&lt;?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?&gt;&quot; /&gt;
+        &lt;input type=&quot;hidden&quot; id=&quot;imgedit-y-&lt;?php echo $post_id; ?&gt;&quot; value=&quot;&lt;?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?&gt;&quot; /&gt;
</ins><span class="cx"> 
</span><span class="cx">         &lt;div id=&quot;imgedit-crop-&lt;?php echo $post_id; ?&gt;&quot; class=&quot;imgedit-crop-wrap&quot;&gt;
</span><span class="cx">         &lt;img id=&quot;image-preview-&lt;?php echo $post_id; ?&gt;&quot; onload=&quot;imageEdit.imgLoaded('&lt;?php echo $post_id; ?&gt;')&quot; src=&quot;&lt;?php echo admin_url( 'admin-ajax.php', 'relative' ); ?&gt;?action=imgedit-preview&amp;amp;_ajax_nonce=&lt;?php echo $nonce; ?&gt;&amp;amp;postid=&lt;?php echo $post_id; ?&gt;&amp;amp;rand=&lt;?php echo rand(1, 99999); ?&gt;&quot; /&gt;
</span><span class="lines">@@ -82,9 +83,11 @@
</span><span class="cx">                 &lt;a class=&quot;imgedit-help-toggle&quot; onclick=&quot;imageEdit.toggleHelp(this);return false;&quot; href=&quot;#&quot;&gt;&lt;strong&gt;&lt;?php _e('Scale Image'); ?&gt;&lt;/strong&gt;&lt;/a&gt;
</span><span class="cx">                 &lt;div class=&quot;imgedit-help&quot;&gt;
</span><span class="cx">                 &lt;p&gt;&lt;?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?&gt;&lt;/p&gt;
</span><ins>+                &lt;?php if ( isset( $meta['width'], $meta['height'] ) ): ?&gt;
</ins><span class="cx">                 &lt;p&gt;&lt;?php printf( __('Original dimensions %s'), $meta['width'] . '&amp;times;' . $meta['height'] ); ?&gt;&lt;/p&gt;
</span><ins>+                &lt;?php endif ?&gt;
</ins><span class="cx">                 &lt;div class=&quot;imgedit-submit&quot;&gt;
</span><del>-                &lt;span class=&quot;nowrap&quot;&gt;&lt;input type=&quot;text&quot; id=&quot;imgedit-scale-width-&lt;?php echo $post_id; ?&gt;&quot; onkeyup=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 1)&quot; onblur=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 1)&quot; style=&quot;width:4em;&quot; value=&quot;&lt;?php echo $meta['width']; ?&gt;&quot; /&gt;&amp;times;&lt;input type=&quot;text&quot; id=&quot;imgedit-scale-height-&lt;?php echo $post_id; ?&gt;&quot; onkeyup=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 0)&quot; onblur=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 0)&quot; style=&quot;width:4em;&quot; value=&quot;&lt;?php echo $meta['height']; ?&gt;&quot; /&gt;
</del><ins>+                &lt;span class=&quot;nowrap&quot;&gt;&lt;input type=&quot;text&quot; id=&quot;imgedit-scale-width-&lt;?php echo $post_id; ?&gt;&quot; onkeyup=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 1)&quot; onblur=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 1)&quot; style=&quot;width:4em;&quot; value=&quot;&lt;?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?&gt;&quot; /&gt;&amp;times;&lt;input type=&quot;text&quot; id=&quot;imgedit-scale-height-&lt;?php echo $post_id; ?&gt;&quot; onkeyup=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 0)&quot; onblur=&quot;imageEdit.scaleChanged(&lt;?php echo $post_id; ?&gt;, 0)&quot; style=&quot;width:4em;&quot; value=&quot;&lt;?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?&gt;&quot; /&gt;
</ins><span class="cx">                 &lt;span class=&quot;imgedit-scale-warn&quot; id=&quot;imgedit-scale-warn-&lt;?php echo $post_id; ?&gt;&quot;&gt;!&lt;/span&gt;&lt;/span&gt;
</span><span class="cx">                 &lt;input type=&quot;button&quot; onclick=&quot;imageEdit.action(&lt;?php echo &quot;$post_id, '$nonce'&quot;; ?&gt;, 'scale')&quot; class=&quot;button-primary&quot; value=&quot;&lt;?php esc_attr_e( 'Scale' ); ?&gt;&quot; /&gt;
</span><span class="cx">                 &lt;/div&gt;
</span><span class="lines">@@ -499,7 +502,7 @@
</span><span class="cx">                                         $delpath = apply_filters('wp_delete_file', $file);
</span><span class="cx">                                         @unlink($delpath);
</span><span class="cx">                                 }
</span><del>-                        } else {
</del><ins>+                        } elseif ( isset( $meta['width'], $meta['height'] ) ) {
</ins><span class="cx">                                 $backup_sizes[&quot;full-$suffix&quot;] = array('width' =&gt; $meta['width'], 'height' =&gt; $meta['height'], 'file' =&gt; $parts['basename']);
</span><span class="cx">                         }
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (23872 => 23873)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2013-03-29 20:50:09 UTC (rev 23872)
+++ trunk/wp-admin/includes/media.php        2013-03-29 20:51:35 UTC (rev 23873)
</span><span class="lines">@@ -1127,7 +1127,7 @@
</span><span class="cx"> 
</span><span class="cx">         $media_dims = '';
</span><span class="cx">         $meta = wp_get_attachment_metadata( $post-&gt;ID );
</span><del>-        if ( is_array( $meta ) &amp;&amp; array_key_exists( 'width', $meta ) &amp;&amp; array_key_exists( 'height', $meta ) )
</del><ins>+        if ( isset( $meta['width'], $meta['height'] ) )
</ins><span class="cx">                 $media_dims .= &quot;&lt;span id='media-dims-$post-&gt;ID'&gt;{$meta['width']}&amp;nbsp;&amp;times;&amp;nbsp;{$meta['height']}&lt;/span&gt; &quot;;
</span><span class="cx">         $media_dims = apply_filters( 'media_meta', $media_dims, $post );
</span><span class="cx"> 
</span><span class="lines">@@ -2368,7 +2368,7 @@
</span><span class="cx"> 
</span><span class="cx">         $media_dims = '';
</span><span class="cx">         $meta = wp_get_attachment_metadata( $post-&gt;ID );
</span><del>-        if ( is_array( $meta ) &amp;&amp; array_key_exists( 'width', $meta ) &amp;&amp; array_key_exists( 'height', $meta ) )
</del><ins>+        if ( isset( $meta['width'], $meta['height'] ) )
</ins><span class="cx">                 $media_dims .= &quot;&lt;span id='media-dims-$post-&gt;ID'&gt;{$meta['width']}&amp;nbsp;&amp;times;&amp;nbsp;{$meta['height']}&lt;/span&gt; &quot;;
</span><span class="cx">         $media_dims = apply_filters( 'media_meta', $media_dims, $post );
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (23872 => 23873)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2013-03-29 20:50:09 UTC (rev 23872)
+++ trunk/wp-includes/media.php        2013-03-29 20:51:35 UTC (rev 23873)
</span><span class="lines">@@ -164,7 +164,7 @@
</span><span class="cx">                         $is_intermediate = true;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        if ( !$width &amp;&amp; !$height &amp;&amp; isset($meta['width'], $meta['height']) ) {
</del><ins>+        if ( !$width &amp;&amp; !$height &amp;&amp; isset( $meta['width'], $meta['height'] ) ) {
</ins><span class="cx">                 // any other type: use the real image
</span><span class="cx">                 $width = $meta['width'];
</span><span class="cx">                 $height = $meta['height'];
</span><span class="lines">@@ -780,8 +780,11 @@
</span><span class="cx">         foreach ( $attachments as $id =&gt; $attachment ) {
</span><span class="cx">                 $link = isset($attr['link']) &amp;&amp; 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
</span><span class="cx">                 $image_meta  = wp_get_attachment_metadata( $id );
</span><del>-                $orientation = ( $image_meta['height'] &gt; $image_meta['width'] ) ? 'portrait' : 'landscape';
</del><span class="cx"> 
</span><ins>+                $orientation = '';
+                if ( isset( $image_meta['height'], $image_meta['width'] ) )
+                        $orientation = ( $image_meta['height'] &gt; $image_meta['width'] ) ? 'portrait' : 'landscape';
+
</ins><span class="cx">                 $output .= &quot;&lt;{$itemtag} class='gallery-item'&gt;&quot;;
</span><span class="cx">                 $output .= &quot;
</span><span class="cx">                         &lt;{$icontag} class='gallery-icon {$orientation}'&gt;
</span><span class="lines">@@ -1626,13 +1629,14 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                $sizes['full'] = array(
-                        'height'      =&gt; $meta['height'],
-                        'width'       =&gt; $meta['width'],
-                        'url'         =&gt; $attachment_url,
-                        'orientation' =&gt; $meta['height'] &gt; $meta['width'] ? 'portrait' : 'landscape',
-                );
</del><ins>+                $sizes['full'] = array( 'url' =&gt; $attachment_url );
</ins><span class="cx"> 
</span><ins>+                if ( isset( $meta['height'], $meta['width'] ) ) {
+                        $sizes['full']['height'] = $meta['height'];
+                        $sizes['full']['width'] = $meta['width'];
+                        $sizes['full']['orientation'] = $meta['height'] &gt; $meta['width'] ? 'portrait' : 'landscape';
+                }
+
</ins><span class="cx">                 $response = array_merge( $response, array( 'sizes' =&gt; $sizes ), $sizes['full'] );
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (23872 => 23873)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2013-03-29 20:50:09 UTC (rev 23872)
+++ trunk/wp-includes/theme.php        2013-03-29 20:51:35 UTC (rev 23873)
</span><span class="lines">@@ -1013,8 +1013,10 @@
</span><span class="cx">                 $header_images[$header_index]['attachment_id'] =  $header-&gt;ID;
</span><span class="cx">                 $header_images[$header_index]['url'] =  $url;
</span><span class="cx">                 $header_images[$header_index]['thumbnail_url'] =  $url;
</span><del>-                $header_images[$header_index]['width'] = $header_data['width'];
-                $header_images[$header_index]['height'] = $header_data['height'];
</del><ins>+                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'];
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return $header_images;
</span></span></pre>
</div>
</div>

</body>
</html>