<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[15455] trunk/wp-includes/update.php: Clean up wp_update_themes().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15455">15455</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-07-22 13:24:41 +0000 (Thu, 22 Jul 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up wp_update_themes(). Fix reporting of active theme. Props josephscott. fixes <a href="http://trac.wordpress.org/ticket/14381">#14381</a> for 3.1</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesupdatephp">trunk/wp-includes/update.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesupdatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/update.php (15454 => 15455)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/update.php        2010-07-22 07:00:22 UTC (rev 15454)
+++ trunk/wp-includes/update.php        2010-07-22 13:24:41 UTC (rev 15455)
</span><span class="lines">@@ -211,36 +211,43 @@
</span><span class="cx">                 require_once( ABSPATH . 'wp-includes/theme.php' );
</span><span class="cx"> 
</span><span class="cx">         $installed_themes = get_themes( );
</span><del>-        $current_theme = get_site_transient( 'update_themes' );
-        if ( ! is_object($current_theme) )
-                $current_theme = new stdClass;
</del><ins>+        $last_update = get_site_transient( 'update_themes' );
+        if ( ! is_object($last_update) )
+                $last_update = new stdClass;
</ins><span class="cx"> 
</span><del>-        $new_option = new stdClass;
-        $new_option-&gt;last_checked = time( );
</del><span class="cx">         $timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
</span><del>-        $time_not_changed = isset( $current_theme-&gt;last_checked ) &amp;&amp; $timeout &gt; ( time( ) - $current_theme-&gt;last_checked );
</del><ins>+        $time_not_changed = isset( $last_update-&gt;last_checked ) &amp;&amp; $timeout &gt; ( time( ) - $last_update-&gt;last_checked );
</ins><span class="cx"> 
</span><span class="cx">         $themes = array();
</span><span class="cx">         $checked = array();
</span><del>-        $themes['current_theme'] = (array) $current_theme;
</del><ins>+        $exclude_fields = array('Template Files', 'Stylesheet Files', 'Status', 'Theme Root', 'Theme Root URI', 'Template Dir', 'Stylesheet Dir', 'Description', 'Tags', 'Screenshot');
+
+        // Put slug of current theme into request.
+        $themes['current_theme'] = get_option( 'stylesheet' );
+
</ins><span class="cx">         foreach ( (array) $installed_themes as $theme_title =&gt; $theme ) {
</span><span class="cx">                 $themes[$theme['Stylesheet']] = array();
</span><span class="cx">                 $checked[$theme['Stylesheet']] = $theme['Version'];
</span><span class="cx"> 
</span><del>-                foreach ( (array) $theme as $key =&gt; $value )
-                        $themes[$theme['Stylesheet']][$key] = $value;
</del><ins>+                $themes[$theme['Stylesheet']]['Name'] = $theme['Name'];
+                $themes[$theme['Stylesheet']]['Version'] = $theme['Version'];
+
+                foreach ( (array) $theme as $key =&gt; $value ) {
+                        if ( !in_array($key, $exclude_fields) )
+                                $themes[$theme['Stylesheet']][$key] = $value;
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $theme_changed = false;
</span><span class="cx">         foreach ( $checked as $slug =&gt; $v ) {
</span><del>-                $new_option-&gt;checked[ $slug ] = $v;
</del><ins>+                $update_request-&gt;checked[ $slug ] = $v;
</ins><span class="cx"> 
</span><del>-                if ( !isset( $current_theme-&gt;checked[ $slug ] ) || strval($current_theme-&gt;checked[ $slug ]) !== strval($v) )
</del><ins>+                if ( !isset( $last_update-&gt;checked[ $slug ] ) || strval($last_update-&gt;checked[ $slug ]) !== strval($v) )
</ins><span class="cx">                         $theme_changed = true;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( isset ( $current_theme-&gt;response ) &amp;&amp; is_array( $current_theme-&gt;response ) ) {
-                foreach ( $current_theme-&gt;response as $slug =&gt; $update_details ) {
</del><ins>+        if ( isset ( $last_update-&gt;response ) &amp;&amp; is_array( $last_update-&gt;response ) ) {
+                foreach ( $last_update-&gt;response as $slug =&gt; $update_details ) {
</ins><span class="cx">                         if ( ! isset($checked[ $slug ]) ) {
</span><span class="cx">                                 $theme_changed = true;
</span><span class="cx">                                 break;
</span><span class="lines">@@ -252,11 +259,9 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // Update last_checked for current to prevent multiple blocking requests if request hangs
</span><del>-        $current_theme-&gt;last_checked = time();
-        set_site_transient( 'update_themes', $current_theme );
</del><ins>+        $last_update-&gt;last_checked = time();
+        set_site_transient( 'update_themes', $last_update );
</ins><span class="cx"> 
</span><del>-        $current_theme-&gt;template = get_option( 'template' );
-
</del><span class="cx">         $options = array(
</span><span class="cx">                 'timeout' =&gt; ( ( defined('DOING_CRON') &amp;&amp; DOING_CRON ) ? 30 : 3),
</span><span class="cx">                 'body'                        =&gt; array( 'themes' =&gt; serialize( $themes ) ),
</span><span class="lines">@@ -271,13 +276,15 @@
</span><span class="cx">         if ( 200 != $raw_response['response']['code'] )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><ins>+        $new_update = new stdClass;
+        $new_update-&gt;last_checked = time( );
</ins><span class="cx">         $response = unserialize( $raw_response['body'] );
</span><span class="cx">         if ( $response ) {
</span><del>-                $new_option-&gt;checked = $checked;
-                $new_option-&gt;response = $response;
</del><ins>+                $new_update-&gt;checked = $checked;
+                $new_update-&gt;response = $response;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        set_site_transient( 'update_themes', $new_option );
</del><ins>+        set_site_transient( 'update_themes', $new_update );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function _maybe_update_core() {
</span></span></pre>
</div>
</div>

</body>
</html>