Make WordPress Core

Changeset 27706


Ignore:
Timestamp:
03/25/2014 12:13:40 PM (11 years ago)
Author:
nacin
Message:

Multisite: Don't set the $super_admins global in grant_super_admin(), revoke_super_admin().

Adds tests and docs.

props jdgrimes.
see #27205.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ms.php

    r27029 r27706  
    687687 * @since 3.0.0
    688688 * @param int $user_id ID of the user to be granted Super Admin privileges.
     689 * @return bool True on success, false on failure. This can fail when the user is
     690 *              already a super admin or when the $super_admins global is defined.
    689691 */
    690692function grant_super_admin( $user_id ) {
    691     global $super_admins;
    692 
    693693    // If global super_admins override is defined, there is nothing to do here.
    694     if ( isset( $super_admins ) )
     694    if ( isset( $GLOBALS['super_admins'] ) ) {
    695695        return false;
     696    }
    696697
    697698    /**
     
    730731 * @since 3.0.0
    731732 * @param int $user_id ID of the user Super Admin privileges to be revoked from.
     733 * @return bool True on success, false on failure. This can fail when the user's email
     734 *              is the network admin email or when the $super_admins global is defined.
    732735 */
    733736function revoke_super_admin( $user_id ) {
    734     global $super_admins;
    735 
    736737    // If global super_admins override is defined, there is nothing to do here.
    737     if ( isset( $super_admins ) )
     738    if ( isset( $GLOBALS['super_admins'] ) ) {
    738739        return false;
     740    }
    739741
    740742    /**
  • trunk/tests/phpunit/tests/ms.php

    r27359 r27706  
    13011301        $this->assertQueryTrue( 'is_author', 'is_archive' );
    13021302    }
     1303
     1304    /**
     1305     * @ticket 27205
     1306     */
     1307    function test_granting_super_admins() {
     1308        if ( isset( $GLOBALS['super_admins'] ) ) {
     1309            $old_global = $GLOBALS['super_admins'];
     1310            unset( $GLOBALS['super_admins'] );
     1311        }
     1312
     1313        $user_id = $this->factory->user->create();
     1314
     1315        $this->assertFalse( is_super_admin( $user_id ) );
     1316        $this->assertFalse( revoke_super_admin( $user_id ) );
     1317        $this->assertTrue( grant_super_admin( $user_id ) );
     1318        $this->assertTrue( is_super_admin( $user_id ) );
     1319        $this->assertFalse( grant_super_admin( $user_id ) );
     1320        $this->assertTrue( revoke_super_admin( $user_id ) );
     1321
     1322        // None of these operations should set the $super_admins global.
     1323        $this->assertFalse( isset( $GLOBALS['super_admins'] ) );
     1324
     1325        // Try with two users.
     1326        $second_user = $this->factory->user->create();
     1327        $this->assertTrue( grant_super_admin( $user_id ) );
     1328        $this->assertTrue( grant_super_admin( $second_user ) );
     1329        $this->assertTrue( is_super_admin( $second_user ) );
     1330        $this->assertTrue( is_super_admin( $user_id ) );
     1331        $this->assertTrue( revoke_super_admin( $user_id ) );
     1332        $this->assertTrue( revoke_super_admin( $second_user ) );
     1333
     1334        if ( isset( $old_global ) ) {
     1335            $GLOBALS['super_admins'] = $old_global;
     1336        }
     1337    }
    13031338}
    13041339
Note: See TracChangeset for help on using the changeset viewer.