Introduce get_super_admins(). Allow hard-coding a global super_admins array and bypassing site options. fixes #12815

git-svn-id: http://svn.automattic.com/wordpress/trunk@14206 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-04-23 20:34:03 +00:00
parent 59589f6dc4
commit bc0947b075
5 changed files with 40 additions and 7 deletions

View File

@ -187,7 +187,7 @@ function confirm_delete_users( $users ) {
<input type="hidden" name="dodelete" />
<?php
wp_nonce_field( 'ms-users-delete' );
$site_admins = get_site_option( 'site_admins', array( 'admin' ) );
$site_admins = get_super_admins();
$admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
@ -811,8 +811,15 @@ function _admin_notice_multisite_activate_plugins_page() {
* @param $user_id
*/
function grant_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
do_action( 'grant_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
$user = new WP_User( $user_id );
@ -832,9 +839,17 @@ function grant_super_admin( $user_id ) {
* @param $user_id
*/
function revoke_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
do_action( 'revoke_super_admin', $user_id );
// Directly fetch site_admins instead of using get_super_admins()
$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
$user = new WP_User( $user_id );
if ( $user->user_email != get_site_option( 'admin_email' ) ) {
if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {

View File

@ -531,7 +531,7 @@ switch ( $_GET['action'] ) {
case 'spam':
$user = new WP_User( $val );
if ( in_array( $user->user_login, get_site_option( 'site_admins', array( 'admin' ) ) ) )
if ( in_array( $user->user_login, get_super_admins() ) )
wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network admnistrator.' ), esc_html( $user->user_login ) ) );
$userfunction = 'all_spam';

View File

@ -199,7 +199,7 @@ if ( isset( $_GET['updated'] ) && $_GET['updated'] == 'true' && ! empty( $_GET['
<tbody id="the-user-list" class="list:user">
<?php if ( $user_list ) {
$class = '';
$super_admins = get_site_option( 'site_admins' );
$super_admins = get_super_admins();
foreach ( (array) $user_list as $user ) {
$class = ( 'alternate' == $class ) ? '' : 'alternate';

View File

@ -121,7 +121,7 @@ if ( !is_multisite() ) {
if ( $delete_role ) // stops users being added to current blog when they are edited
delete_user_meta( $user_id, $blog_prefix . 'capabilities' );
if ( is_multisite() && !IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) )
if ( is_multisite() && !IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) && empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) )
empty( $_POST['super_admin'] ) ? revoke_super_admin( $user_id ) : grant_super_admin( $user_id );
}
@ -235,7 +235,7 @@ else
echo '<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
?>
</select>
<?php if ( is_multisite() && current_user_can( 'manage_network_options' ) ) { ?>
<?php if ( is_multisite() && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?>
<p><label><input type="checkbox" id="super_admin" name="super_admin"<?php checked( is_super_admin( $profileuser->ID ) ); ?> /> <?php _e( 'Grant this user super admin privileges for the Network.'); ?></label></p>
<?php } ?>
</td></tr>

View File

@ -1170,6 +1170,24 @@ function remove_role( $role ) {
return $wp_roles->remove_role( $role );
}
/**
* 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') );
}
/**
* Determine if user is a site admin.
*
@ -1190,8 +1208,8 @@ function is_super_admin( $user_id = false ) {
$user = new WP_User($user_id);
if ( is_multisite() ) {
$site_admins = get_site_option( 'site_admins', array('admin') );
if ( is_array( $site_admins ) && in_array( $user->user_login, $site_admins ) )
$super_admins = get_super_admins();
if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) )
return true;
} else {
if ( $user->has_cap('delete_users') )