<!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>[14206] trunk: Introduce get_super_admins().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14206">14206</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-04-23 20:34:03 +0000 (Fri, 23 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce get_super_admins().  Allow hard-coding a global super_admins array and bypassing site options. fixes <a href="http://trac.wordpress.org/ticket/12815">#12815</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmsphp">trunk/wp-admin/includes/ms.php</a></li>
<li><a href="#trunkwpadminmseditphp">trunk/wp-admin/ms-edit.php</a></li>
<li><a href="#trunkwpadminmsusersphp">trunk/wp-admin/ms-users.php</a></li>
<li><a href="#trunkwpadminusereditphp">trunk/wp-admin/user-edit.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ms.php (14205 => 14206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ms.php        2010-04-23 20:21:09 UTC (rev 14205)
+++ trunk/wp-admin/includes/ms.php        2010-04-23 20:34:03 UTC (rev 14206)
</span><span class="lines">@@ -187,7 +187,7 @@
</span><span class="cx">         &lt;input type=&quot;hidden&quot; name=&quot;dodelete&quot; /&gt;
</span><span class="cx">     &lt;?php
</span><span class="cx">         wp_nonce_field( 'ms-users-delete' );
</span><del>-        $site_admins = get_site_option( 'site_admins', array( 'admin' ) );
</del><ins>+        $site_admins = get_super_admins();
</ins><span class="cx">         $admin_out = &quot;&lt;option value='$current_user-&gt;ID'&gt;$current_user-&gt;user_login&lt;/option&gt;&quot;;
</span><span class="cx"> 
</span><span class="cx">         foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key =&gt; $val ) {
</span><span class="lines">@@ -811,8 +811,15 @@
</span><span class="cx">  * @param $user_id
</span><span class="cx">  */
</span><span class="cx"> function grant_super_admin( $user_id ) {
</span><ins>+        global $super_admins;
+
+        // If global super_admins override is defined, there is nothing to do here.
+        if ( isset($super_admins) )
+                return false;
+
</ins><span class="cx">         do_action( 'grant_super_admin', $user_id );
</span><span class="cx"> 
</span><ins>+        // Directly fetch site_admins instead of using get_super_admins()
</ins><span class="cx">         $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
</span><span class="cx"> 
</span><span class="cx">         $user = new WP_User( $user_id );
</span><span class="lines">@@ -832,9 +839,17 @@
</span><span class="cx">  * @param $user_id
</span><span class="cx">  */
</span><span class="cx"> function revoke_super_admin( $user_id ) {
</span><ins>+        global $super_admins;
+
+        // If global super_admins override is defined, there is nothing to do here.
+        if ( isset($super_admins) )
+                return false;
+
</ins><span class="cx">         do_action( 'revoke_super_admin', $user_id );
</span><span class="cx"> 
</span><ins>+        // Directly fetch site_admins instead of using get_super_admins()
</ins><span class="cx">         $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
</span><ins>+
</ins><span class="cx">         $user = new WP_User( $user_id );
</span><span class="cx">         if ( $user-&gt;user_email != get_site_option( 'admin_email' ) ) {
</span><span class="cx">                 if ( false !== ( $key = array_search( $user-&gt;user_login, $super_admins ) ) ) {
</span></span></pre></div>
<a id="trunkwpadminmseditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-edit.php (14205 => 14206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-edit.php        2010-04-23 20:21:09 UTC (rev 14205)
+++ trunk/wp-admin/ms-edit.php        2010-04-23 20:34:03 UTC (rev 14206)
</span><span class="lines">@@ -531,7 +531,7 @@
</span><span class="cx"> 
</span><span class="cx">                                                 case 'spam':
</span><span class="cx">                                                         $user = new WP_User( $val );
</span><del>-                                                        if ( in_array( $user-&gt;user_login, get_site_option( 'site_admins', array( 'admin' ) ) ) )
</del><ins>+                                                        if ( in_array( $user-&gt;user_login, get_super_admins() ) )
</ins><span class="cx">                                                                 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network admnistrator.' ), esc_html( $user-&gt;user_login ) ) );
</span><span class="cx"> 
</span><span class="cx">                                                         $userfunction = 'all_spam';
</span></span></pre></div>
<a id="trunkwpadminmsusersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/ms-users.php (14205 => 14206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/ms-users.php        2010-04-23 20:21:09 UTC (rev 14205)
+++ trunk/wp-admin/ms-users.php        2010-04-23 20:34:03 UTC (rev 14206)
</span><span class="lines">@@ -199,7 +199,7 @@
</span><span class="cx">                         &lt;tbody id=&quot;the-user-list&quot; class=&quot;list:user&quot;&gt;
</span><span class="cx">                         &lt;?php if ( $user_list ) {
</span><span class="cx">                                 $class = '';
</span><del>-                                $super_admins = get_site_option( 'site_admins' );
</del><ins>+                                $super_admins = get_super_admins();
</ins><span class="cx">                                 foreach ( (array) $user_list as $user ) {
</span><span class="cx">                                         $class = ( 'alternate' == $class ) ? '' : 'alternate';
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminusereditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/user-edit.php (14205 => 14206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/user-edit.php        2010-04-23 20:21:09 UTC (rev 14205)
+++ trunk/wp-admin/user-edit.php        2010-04-23 20:34:03 UTC (rev 14206)
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx">         if ( $delete_role ) // stops users being added to current blog when they are edited
</span><span class="cx">                 delete_user_meta( $user_id, $blog_prefix . 'capabilities' );
</span><span class="cx"> 
</span><del>-        if ( is_multisite() &amp;&amp; !IS_PROFILE_PAGE &amp;&amp; current_user_can( 'manage_network_options' ) &amp;&amp; empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) )
</del><ins>+        if ( is_multisite() &amp;&amp; !IS_PROFILE_PAGE &amp;&amp; current_user_can( 'manage_network_options' ) &amp;&amp; !isset($super_admins) &amp;&amp; empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) )
</ins><span class="cx">                 empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -235,7 +235,7 @@
</span><span class="cx">         echo '&lt;option value=&quot;&quot; selected=&quot;selected&quot;&gt;' . __('&amp;mdash; No role for this blog &amp;mdash;') . '&lt;/option&gt;';
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;/select&gt;
</span><del>-&lt;?php if ( is_multisite() &amp;&amp; current_user_can( 'manage_network_options' ) ) { ?&gt;
</del><ins>+&lt;?php if ( is_multisite() &amp;&amp; current_user_can( 'manage_network_options' ) &amp;&amp; !isset($super_admins) ) { ?&gt;
</ins><span class="cx"> &lt;p&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; id=&quot;super_admin&quot; name=&quot;super_admin&quot;&lt;?php checked( is_super_admin( $profileuser-&gt;ID ) ); ?&gt; /&gt; &lt;?php _e( 'Grant this user super admin privileges for the Network.'); ?&gt;&lt;/label&gt;&lt;/p&gt;
</span><span class="cx"> &lt;?php } ?&gt;
</span><span class="cx"> &lt;/td&gt;&lt;/tr&gt;
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (14205 => 14206)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2010-04-23 20:21:09 UTC (rev 14205)
+++ trunk/wp-includes/capabilities.php        2010-04-23 20:34:03 UTC (rev 14206)
</span><span class="lines">@@ -1171,6 +1171,24 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Retrieve a list of super admins.
+ *
+ * @since 3.0.0
+ * 
+ * @uses $super_admins Super admins global variable, if set.
+ * 
+ * @return array List of super admin logins
+ */
+function get_super_admins() {
+        global $super_admins;
+
+        if ( isset($super_admins) )
+                return $super_admins;
+        else
+                return get_site_option( 'site_admins', array('admin') );
+}
+
+/**
</ins><span class="cx">  * Determine if user is a site admin.
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span><span class="lines">@@ -1190,8 +1208,8 @@
</span><span class="cx">         $user = new WP_User($user_id);
</span><span class="cx"> 
</span><span class="cx">         if ( is_multisite() ) {
</span><del>-                $site_admins = get_site_option( 'site_admins', array('admin') );
-                if ( is_array( $site_admins ) &amp;&amp; in_array( $user-&gt;user_login, $site_admins ) )
</del><ins>+                $super_admins = get_super_admins();
+                if ( is_array( $super_admins ) &amp;&amp; in_array( $user-&gt;user_login, $super_admins ) )
</ins><span class="cx">                         return true;
</span><span class="cx">         } else {
</span><span class="cx">                 if ( $user-&gt;has_cap('delete_users') )
</span></span></pre>
</div>
</div>

</body>
</html>