Make WordPress Core

Ticket #39170: 39170.diff

File 39170.diff, 2.9 KB (added by flixos90, 8 years ago)
  • src/wp-admin/user-edit.php

     
    364364</select></td></tr>
    365365<?php endif; //!IS_PROFILE_PAGE
    366366
    367 if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_can( 'manage_network_options' ) && !isset($super_admins) ) { ?>
     367if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && ! isset( $super_admins ) ) { ?>
    368368<tr class="user-super-admin-wrap"><th><?php _e('Super Admin'); ?></th>
    369369<td>
    370 <?php if ( $profileuser->user_email != get_site_option( 'admin_email' ) || ! is_super_admin( $profileuser->ID ) ) : ?>
    371370<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>
    372 <?php else : ?>
    373 <p><?php _e( 'Super admin privileges cannot be removed because this user has the network admin email.' ); ?></p>
    374 <?php endif; ?>
    375371</td></tr>
    376372<?php } ?>
    377373
  • src/wp-includes/capabilities.php

     
    769769 * Revokes Super Admin privileges.
    770770 *
    771771 * @since 3.0.0
     772 * @since 4.8.0 Super admin privileges can be revoked regardless of email address.
    772773 *
    773774 * @global array $super_admins
    774775 *
     
    795796        $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    796797
    797798        $user = get_userdata( $user_id );
    798         if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) {
     799        if ( $user ) {
    799800                if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
    800801                        unset( $super_admins[$key] );
    801802                        update_site_option( 'site_admins', $super_admins );
  • tests/phpunit/tests/user/multisite.php

     
    424424
    425425                $wp_roles->remove_role( $role );
    426426        }
     427
     428        /**
     429         * @ticket 39170
     430         */
     431        public function test_revoke_super_admin_with_network_email() {
     432                if ( isset( $GLOBALS['super_admins'] ) ) {
     433                        $old_global = $GLOBALS['super_admins'];
     434                        unset( $GLOBALS['super_admins'] );
     435                }
     436
     437                $old_network_email = get_site_option( 'admin_email' );
     438
     439                $email_address = 'superadmin333@example.org';
     440                $user_id = self::factory()->user->create( array(
     441                        'user_email' => $email_address,
     442                ) );
     443                grant_super_admin( $user_id );
     444                update_site_option( 'admin_email', $email_address );
     445
     446                $result = revoke_super_admin( $user_id );
     447
     448                update_site_option( 'admin_email', $old_network_email );
     449
     450                if ( isset( $old_global ) ) {
     451                        $GLOBALS['super_admins'] = $old_global;
     452                }
     453
     454                $this->assertTrue( $result );
     455        }
    427456}
    428457
    429458endif ;