<!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>[12755] trunk: Multisite and formatting cleanups.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12755">12755</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-01-18 23:34:36 +0000 (Mon, 18 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Multisite and formatting cleanups. Introduce get_allowed_themes(). see <a href="http://trac.wordpress.org/ticket/11644">#11644</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesthemephp">trunk/wp-admin/includes/theme.php</a></li>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwpadminthemesphp">trunk/wp-admin/themes.php</a></li>
<li><a href="#trunkwpincludesloadphp">trunk/wp-includes/load.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/theme.php (12754 => 12755)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/theme.php        2010-01-18 22:34:16 UTC (rev 12754)
+++ trunk/wp-admin/includes/theme.php        2010-01-18 23:34:36 UTC (rev 12755)
</span><span class="lines">@@ -117,6 +117,45 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Get the allowed themes for the current blog.
+ *
+ * @since 3.0
+ *
+ * @uses get_themes()
+ * @uses current_theme_info()
+ * @uses get_site_allowed_themes()
+ * @uses wpmu_get_blog_allowedthemes
+ *
+ * @return array $themes Array of allowed themes.
+ */
+function get_allowed_themes() {
+        if ( !is_multisite() )
+                return get_themes();
+
+        $themes = get_themes();
+        $ct = current_theme_info();
+        $allowed_themes = apply_filters(&quot;allowed_themes&quot;, get_site_allowed_themes() );
+        if ( $allowed_themes == false )
+                $allowed_themes = array();
+
+        $blog_allowed_themes = wpmu_get_blog_allowedthemes();
+        if ( is_array( $blog_allowed_themes ) )
+                $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
+
+        if ( isset( $allowed_themes[ wp_specialchars( $ct-&gt;stylesheet ) ] ) == false )
+                $allowed_themes[ wp_specialchars( $ct-&gt;stylesheet ) ] = true;
+
+        reset( $themes );
+        foreach ( $themes as $key =&gt; $theme ) {
+                if ( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false )
+                        unset( $themes[ $key ] );
+        }
+        reset( $themes );
+        
+        return $themes;
+}
+
+/**
</ins><span class="cx">  * Get the Page Templates available in this theme
</span><span class="cx">  *
</span><span class="cx">  * @since unknown
</span></span></pre></div>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (12754 => 12755)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2010-01-18 22:34:16 UTC (rev 12754)
+++ trunk/wp-admin/includes/user.php        2010-01-18 23:34:36 UTC (rev 12755)
</span><span class="lines">@@ -197,11 +197,11 @@
</span><span class="cx">  */
</span><span class="cx"> function get_author_user_ids() {
</span><span class="cx">         global $wpdb;
</span><del>-        if( !is_multisite() ) {
</del><ins>+        if ( !is_multisite() )
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'user_level';
</span><del>-        } else {
</del><ins>+        else
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
</span><del>-        }
</del><ins>+
</ins><span class="cx">         return $wpdb-&gt;get_col( $wpdb-&gt;prepare(&quot;SELECT user_id FROM $wpdb-&gt;usermeta WHERE meta_key = %s AND meta_value != '0'&quot;, $level_key) );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -220,7 +220,7 @@
</span><span class="cx"> 
</span><span class="cx">         $editable = get_editable_user_ids( $user_id );
</span><span class="cx"> 
</span><del>-        if( !$editable ) {
</del><ins>+        if ( !$editable ) {
</ins><span class="cx">                 return false;
</span><span class="cx">         } else {
</span><span class="cx">                 $editable = join(',', $editable);
</span><span class="lines">@@ -252,11 +252,11 @@
</span><span class="cx">                 else
</span><span class="cx">                         return array();
</span><span class="cx">         }
</span><del>-        if( !is_multisite() ) {
</del><ins>+
+        if ( !is_multisite() )
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'user_level';
</span><del>-        } else {
</del><ins>+        else
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         $query = $wpdb-&gt;prepare(&quot;SELECT user_id FROM $wpdb-&gt;usermeta WHERE meta_key = %s&quot;, $level_key);
</span><span class="cx">         if ( $exclude_zeros )
</span><span class="lines">@@ -302,11 +302,10 @@
</span><span class="cx"> function get_nonauthor_user_ids() {
</span><span class="cx">         global $wpdb;
</span><span class="cx"> 
</span><del>-        if ( !is_multisite() ) {
</del><ins>+        if ( !is_multisite() )
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'user_level';
</span><del>-        } else {
</del><ins>+        else
</ins><span class="cx">                 $level_key = $wpdb-&gt;get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         return $wpdb-&gt;get_col( $wpdb-&gt;prepare(&quot;SELECT user_id FROM $wpdb-&gt;usermeta WHERE meta_key = %s AND meta_value = '0'&quot;, $level_key) );
</span><span class="cx"> }
</span><span class="lines">@@ -332,7 +331,7 @@
</span><span class="cx"> 
</span><span class="cx">         $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC';
</span><span class="cx"> 
</span><del>-        if( !$editable ) {
</del><ins>+        if ( !$editable ) {
</ins><span class="cx">                 $other_unpubs = '';
</span><span class="cx">         } else {
</span><span class="cx">                 $editable = join(',', $editable);
</span><span class="lines">@@ -675,11 +674,11 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;query_from_where = &quot;FROM $wpdb-&gt;users&quot;;
</span><del>-                if ( $this-&gt;role )
</del><ins>+                if ( $this-&gt;role ) {
</ins><span class="cx">                         $this-&gt;query_from_where .= $wpdb-&gt;prepare(&quot; INNER JOIN $wpdb-&gt;usermeta ON $wpdb-&gt;users.ID = $wpdb-&gt;usermeta.user_id WHERE $wpdb-&gt;usermeta.meta_key = '{$wpdb-&gt;prefix}capabilities' AND $wpdb-&gt;usermeta.meta_value LIKE %s&quot;, '%' . $this-&gt;role . '%');
</span><del>-                elseif ( !is_multisite() )
</del><ins>+                } elseif ( !is_multisite() ) {
</ins><span class="cx">                         $this-&gt;query_from_where .= &quot; WHERE 1=1&quot;;
</span><del>-                else {
</del><ins>+                } else {
</ins><span class="cx">                         $level_key = $wpdb-&gt;get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
</span><span class="cx">                         $this-&gt;query_from_where .= &quot;, $wpdb-&gt;usermeta WHERE $wpdb-&gt;users.ID = $wpdb-&gt;usermeta.user_id AND meta_key = '{$level_key}'&quot;;
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkwpadminthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/themes.php (12754 => 12755)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/themes.php        2010-01-18 22:34:16 UTC (rev 12754)
+++ trunk/wp-admin/themes.php        2010-01-18 23:34:36 UTC (rev 12755)
</span><span class="lines">@@ -12,30 +12,6 @@
</span><span class="cx"> if ( !current_user_can('switch_themes') )
</span><span class="cx">         wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
</span><span class="cx"> 
</span><del>-if ( is_multisite() ) {
-        $themes = get_themes();
-        $ct = current_theme_info();
-        $allowed_themes = apply_filters(&quot;allowed_themes&quot;, get_site_allowed_themes() );
-        if ( $allowed_themes == false )
-                $allowed_themes = array();
-
-        $blog_allowed_themes = wpmu_get_blog_allowedthemes();
-        if ( is_array( $blog_allowed_themes ) )
-                $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
-        if ( $blog_id != 1 )
-                unset( $allowed_themes[ &quot;h3&quot; ] );
-
-        if ( isset( $allowed_themes[ wp_specialchars( $ct-&gt;stylesheet ) ] ) == false )
-                $allowed_themes[ wp_specialchars( $ct-&gt;stylesheet ) ] = true;
-
-        reset( $themes );
-        foreach ( $themes as $key =&gt; $theme ) {
-                if ( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) {
-                        unset( $themes[ $key ] );
-                }
-        }
-        reset( $themes );
-}
</del><span class="cx"> if ( isset($_GET['action']) ) {
</span><span class="cx">         if ( 'activate' == $_GET['action'] ) {
</span><span class="cx">                 check_admin_referer('switch-theme_' . $_GET['template']);
</span><span class="lines">@@ -85,8 +61,7 @@
</span><span class="cx"> &lt;?php endif; ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><del>-if ( !is_multisite() )
-        $themes = get_themes();
</del><ins>+$themes = get_allowed_themes();
</ins><span class="cx"> $ct = current_theme_info();
</span><span class="cx"> unset($themes[$ct-&gt;name]);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/load.php (12754 => 12755)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/load.php        2010-01-18 22:34:16 UTC (rev 12754)
+++ trunk/wp-includes/load.php        2010-01-18 23:34:36 UTC (rev 12755)
</span><span class="lines">@@ -260,20 +260,17 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         wp_cache_init();
</span><ins>+
</ins><span class="cx">         if ( function_exists('wp_cache_add_global_groups') ) {
</span><del>-                        if( is_multisite() ) {
-                                        wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss'));
-                        } else {
-                                wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient'));
-                        }
</del><ins>+                wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss'));
</ins><span class="cx">                 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function wp_not_installed() {
</span><span class="cx">         if ( is_multisite() ) {
</span><del>-                        if ( !is_blog_installed() &amp;&amp; !defined('WP_INSTALLING') )
-                                        die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) ); // have to die here ~ Mark
</del><ins>+                if ( !is_blog_installed() &amp;&amp; !defined('WP_INSTALLING') )
+                        die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) ); // have to die here
</ins><span class="cx">         } elseif ( !is_blog_installed() &amp;&amp; (strpos($_SERVER['PHP_SELF'], 'install.php') === false &amp;&amp; !defined('WP_INSTALLING')) ) {
</span><span class="cx">                 if ( defined('WP_SITEURL') )
</span><span class="cx">                         $link = WP_SITEURL . '/wp-admin/install.php';
</span><span class="lines">@@ -293,13 +290,13 @@
</span><span class="cx">         if ( is_dir( WPMU_PLUGIN_DIR ) ) {
</span><span class="cx">                 if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) {
</span><span class="cx">                         $mu_plugins = array ();
</span><del>-                        while ( ( $plugin = readdir( $dh ) ) !== false )
</del><ins>+                        while ( ( $plugin = readdir( $dh ) ) !== false ) {
</ins><span class="cx">                                 if ( substr( $plugin, -4 ) == '.php' )
</span><span class="cx">                                         $mu_plugins[] = $plugin;
</span><ins>+                        }
</ins><span class="cx">                         closedir( $dh );
</span><del>-                                        if( is_multisite() )
-                                        sort( $mu_plugins );
-                        foreach( $mu_plugins as $mu_plugin )
</del><ins>+                        sort( $mu_plugins );
+                        foreach ( $mu_plugins as $mu_plugin )
</ins><span class="cx">                                 include_once( WPMU_PLUGIN_DIR . '/' . $mu_plugin );
</span><span class="cx">                 }
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>