<!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>[20193] trunk: Updates to WP_Theme, wp_get_themes(), and related deprecated functions, after [UT570] [UT578] [UT579].</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/20193">20193</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-03-15 15:39:21 +0000 (Thu, 15 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Updates to WP_Theme, wp_get_themes(), and related deprecated functions, after [UT570] [UT578] [UT579]. see <a href="http://core.trac.wordpress.org/ticket/20103">#20103</a>.
 * ['Template Files'] and ['Stylesheet Files'] need to return files from the parent theme as well.
 * Don't strip links from the Author header. Some themes rely on the previous behavior, such as to link multiple authors (Sandbox, for example.) Don't restore links to the Name, that's just a bad idea.
 * Ensure we are always passing around arrays in get_files/scandir.
 * Better inline doc for wp_get_themes() arguments.
 * Introduce a 'force' flag for search_theme_directories() to re-scan, rather than return the cache. We will use this to re-build the theme_roots transient in get_theme_roots(), but it is more helpful for unit tests. Since search_theme_directories() is cached, don't cache again in wp_get_themes(). (Again benefits testing.)
 * Handle duplicate theme names in the old get_themes() when two themes match (and neither are a default theme, which is already handled). wp_get_themes() will consider both names to be the same; this is just for back compat since get_themes() is keyed by name.
 * Include an old array key in wp_broken_themes().</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesdeprecatedphp">trunk/wp-admin/includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesclasswpthemephp">trunk/wp-includes/class-wp-theme.php</a></li>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/deprecated.php (20192 => 20193)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/deprecated.php        2012-03-15 13:58:27 UTC (rev 20192)
+++ trunk/wp-admin/includes/deprecated.php        2012-03-15 15:39:21 UTC (rev 20193)
</span><span class="lines">@@ -917,8 +917,10 @@
</span><span class="cx">         $themes = wp_get_themes( array( 'errors' =&gt; true ) );
</span><span class="cx">         $broken = array();
</span><span class="cx">         foreach ( $themes as $theme ) {
</span><del>-                $broken[ $theme-&gt;get('Name') ] = array(
-                        'Title' =&gt; $theme-&gt;get('Name'),
</del><ins>+                $name = $theme-&gt;get('Name');
+                $broken[ $name ] = array(
+                        'Name' =&gt; $name,
+                        'Title' =&gt; $name,
</ins><span class="cx">                         'Description' =&gt; $theme-&gt;errors()-&gt;get_error_message(),
</span><span class="cx">                 );
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpincludesclasswpthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-theme.php (20192 => 20193)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-theme.php        2012-03-15 13:58:27 UTC (rev 20192)
+++ trunk/wp-includes/class-wp-theme.php        2012-03-15 15:39:21 UTC (rev 20193)
</span><span class="lines">@@ -384,12 +384,12 @@
</span><span class="cx">                         case 'Stylesheet' :
</span><span class="cx">                                 return $this-&gt;get_stylesheet();
</span><span class="cx">                         case 'Template Files' :
</span><del>-                                $files = $this-&gt;get_files('php');
</del><ins>+                                $files = $this-&gt;get_files('php', true);
</ins><span class="cx">                                 foreach ( $files as &amp;$file )
</span><span class="cx">                                         $file = $this-&gt;theme_root . '/' . $file;
</span><span class="cx">                                 return $files;
</span><span class="cx">                         case 'Stylesheet Files' :
</span><del>-                                $files = $this-&gt;get_files('css');
</del><ins>+                                $files = $this-&gt;get_files('css', true);
</ins><span class="cx">                                 foreach ( $files as &amp;$file )
</span><span class="cx">                                         $file = $this-&gt;theme_root . '/' . $file;
</span><span class="cx">                                 return $files;
</span><span class="lines">@@ -555,7 +555,6 @@
</span><span class="cx">                                 }
</span><span class="cx">                                 // Fall through otherwise.
</span><span class="cx">                         case 'Name' :
</span><del>-                        case 'Author' :
</del><span class="cx">                                 static $header_tags = array(
</span><span class="cx">                                         'abbr'    =&gt; array( 'title' =&gt; true ),
</span><span class="cx">                                         'acronym' =&gt; array( 'title' =&gt; true ),
</span><span class="lines">@@ -565,6 +564,8 @@
</span><span class="cx">                                 );
</span><span class="cx">                                 $value = wp_kses( $value, $header_tags );
</span><span class="cx">                                 break;
</span><ins>+                        case 'Author' :
+                                // There shouldn't be anchor tags in Author, but some themes like to be challenging.
</ins><span class="cx">                         case 'Description' :
</span><span class="cx">                                 static $header_tags_with_a = array(
</span><span class="cx">                                         'a'       =&gt; array( 'href' =&gt; true, 'title' =&gt; true ),
</span><span class="lines">@@ -935,7 +936,9 @@
</span><span class="cx">                         if ( $include_parent_files || ! $this-&gt;is_child_theme() )
</span><span class="cx">                                 // Template files can be one level down for the purposes of the theme editor, so this should be $depth = 1.
</span><span class="cx">                                 // Todo: We ignore this for now, but this is why the branching is weird.
</span><del>-                                $files = (array) self::scandir( $this-&gt;get_template_directory(), $this-&gt;get_template(), array( 'php', 'css' ) );
</del><ins>+                                $files = self::scandir( $this-&gt;get_template_directory(), $this-&gt;get_template(), array( 'php', 'css' ) );
+                        else
+                                $files = array();
</ins><span class="cx">                         if ( $this-&gt;is_child_theme() )
</span><span class="cx">                                 $files = array_merge_recursive( $files, (array) self::scandir( $this-&gt;get_stylesheet_directory(), $this-&gt;get_stylesheet(), array( 'php', 'css' ) ) );
</span><span class="cx">                         foreach ( $files as &amp;$group )
</span><span class="lines">@@ -989,15 +992,15 @@
</span><span class="cx">          * @depth int How deep to search for files. Optional, defaults to a flat scan (0 depth).
</span><span class="cx">          */
</span><span class="cx">         private static function scandir( $path, $relative_path, $extensions, $depth = 0 ) {
</span><del>-                if ( is_array( $extensions ) )
-                        $extensions = implode( '|', $extensions );
-
</del><span class="cx">                 if ( ! is_dir( $path ) )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><span class="cx">                 $results = scandir( $path );
</span><del>-                $files = array();
</del><span class="cx"> 
</span><ins>+                $extensions = (array) $extensions;
+                $files = array_fill_keys( $extensions, array() );
+                $extensions = implode( '|', $extensions );
+
</ins><span class="cx">                 foreach ( $results as $result ) {
</span><span class="cx">                         if ( '.' == $result || '..' == $result )
</span><span class="cx">                                 continue;
</span><span class="lines">@@ -1007,10 +1010,7 @@
</span><span class="cx">                                 $found = self::scandir( $path . '/' . $result, $relative_path . '/' . $result, $extensions, $depth - 1 );
</span><span class="cx">                                 $files = array_merge_recursive( $files, $found );
</span><span class="cx">                         } elseif ( preg_match( '~\.(' . $extensions . ')$~', $result, $match ) ) {
</span><del>-                                if ( ! isset( $files[ $match[1] ] ) )
-                                        $files[ $match[1] ] = array( $relative_path . '/'. $result );
-                                else
-                                        $files[ $match[1] ][] = $relative_path . '/' . $result;
</del><ins>+                                $files[ $match[1] ][] = $relative_path . '/' . $result;
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">                 return $files;
</span></span></pre></div>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (20192 => 20193)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2012-03-15 13:58:27 UTC (rev 20192)
+++ trunk/wp-includes/deprecated.php        2012-03-15 15:39:21 UTC (rev 20193)
</span><span class="lines">@@ -2933,7 +2933,11 @@
</span><span class="cx">         $wp_themes = array();
</span><span class="cx"> 
</span><span class="cx">         foreach ( $themes as $theme ) {
</span><del>-                $wp_themes[ $theme-&gt;get('Name') ] = $theme;
</del><ins>+                $name = $theme-&gt;get('Name');
+                if ( isset( $wp_themes[ $name ] ) )
+                        $wp_themes[ $name . '/' . $theme-&gt;get_stylesheet() ] = $theme;
+                else
+                        $wp_themes[ $name ] = $theme;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return $wp_themes;
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (20192 => 20193)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2012-03-15 13:58:27 UTC (rev 20192)
+++ trunk/wp-includes/theme.php        2012-03-15 15:39:21 UTC (rev 20193)
</span><span class="lines">@@ -9,14 +9,19 @@
</span><span class="cx"> /**
</span><span class="cx">  * Returns an array of WP_Theme objects based on the arguments.
</span><span class="cx">  *
</span><del>- * Despite advances over get_themes(), this function is still quite expensive, and grows
</del><ins>+ * Despite advances over get_themes(), this function is quite expensive, and grows
</ins><span class="cx">  * linearly with additional themes. Stick to wp_get_theme() if possible.
</span><span class="cx">  *
</span><span class="cx">  * @since 3.4.0
</span><span class="cx">  *
</span><del>- * @param array $args Arguments. Currently 'errors' (defaults to false), 'allowed'
- *         (true, false; null for either; defaults to null; only applies to multisite), and 'blog_id'
- *         (defaults to current blog; used to find allowed themes; only applies to multisite).
</del><ins>+ * @param array $args The search arguments. Optional.
+ * - errors      mixed  True to return themes with errors, false to return themes without errors, null
+ *                      to return all themes. Defaults to false.
+ * - allowed     mixed  (Multisite) True to return only allowed themes for a site. False to return only
+ *                      disallowed themes for a site. 'site' to return only site-allowed themes. 'network'
+ *                      to return only network-allowed themes. Null to return all themes. Defaults to null.
+ * - blog_id     int    (Multisite) The blog ID used to calculate which themes are allowed. Defaults to 0,
+ *                      synonymous for the current blog.
</ins><span class="cx">  * @return Array of WP_Theme objects.
</span><span class="cx">  */
</span><span class="cx"> function wp_get_themes( $args = array() ) {
</span><span class="lines">@@ -25,25 +30,23 @@
</span><span class="cx">         $defaults = array( 'errors' =&gt; false, 'allowed' =&gt; null, 'blog_id' =&gt; 0 );
</span><span class="cx">         $args = wp_parse_args( $args, $defaults );
</span><span class="cx"> 
</span><del>-        static $_theme_directories, $_themes = array();
-        if ( ! isset( $_theme_directories ) ) {
-                $_theme_directories = search_theme_directories();
-                if ( count( $wp_theme_directories ) &gt; 1 ) {
-                        // Make sure the current theme wins out, in case search_theme_directories() picks the wrong
-                        // one in the case of a conflict. (Normally, last registered theme root wins.)
-                        $current_theme = get_stylesheet();
</del><ins>+        $theme_directories = search_theme_directories();
+
+        if ( count( $wp_theme_directories ) &gt; 1 ) {
+                // Make sure the current theme wins out, in case search_theme_directories() picks the wrong
+                // one in the case of a conflict. (Normally, last registered theme root wins.)
+                $current_theme = get_stylesheet();
+                if ( isset( $theme_directories[ $current_theme ] ) ) {
</ins><span class="cx">                         $root_of_current_theme = get_raw_theme_root( $current_theme );
</span><span class="cx">                         if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) )
</span><span class="cx">                                 $root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
</span><del>-                        $_theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
</del><ins>+                        $theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( empty( $_theme_directories ) )
</del><ins>+        if ( empty( $theme_directories ) )
</ins><span class="cx">                 return array();
</span><span class="cx"> 
</span><del>-        $theme_directories = $_theme_directories;
-
</del><span class="cx">         if ( is_multisite() &amp;&amp; null !== $args['allowed'] ) {
</span><span class="cx">                 $allowed = $args['allowed'];
</span><span class="cx">                 if ( 'network' === $allowed )
</span><span class="lines">@@ -355,7 +358,7 @@
</span><span class="cx"> 
</span><span class="cx">         $theme_roots = get_site_transient( 'theme_roots' );
</span><span class="cx">         if ( false === $theme_roots ) {
</span><del>-                search_theme_directories(); // Regenerate the transient.
</del><ins>+                search_theme_directories( true ); // Regenerate the transient.
</ins><span class="cx">                 $theme_roots = get_site_transient( 'theme_roots' );
</span><span class="cx">         }
</span><span class="cx">         return $theme_roots;
</span><span class="lines">@@ -390,15 +393,16 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.9.0
</span><span class="cx">  *
</span><ins>+ * @param bool $force Optional. Whether to force a new directory scan. Defaults to false.
</ins><span class="cx">  * @return array Valid themes found
</span><span class="cx">  */
</span><del>-function search_theme_directories() {
</del><ins>+function search_theme_directories( $force = false ) {
</ins><span class="cx">         global $wp_theme_directories;
</span><span class="cx">         if ( empty( $wp_theme_directories ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         static $found_themes;
</span><del>-        if ( isset( $found_themes ) )
</del><ins>+        if ( ! $force &amp;&amp; isset( $found_themes ) )
</ins><span class="cx">                 return $found_themes;
</span><span class="cx"> 
</span><span class="cx">         $found_themes = array();
</span></span></pre>
</div>
</div>

</body>
</html>