Make WordPress Core


Ignore:
Timestamp:
03/19/2018 08:28:28 PM (8 years ago)
Author:
ocean90
Message:

Users: Use promote_users for role updates in edit_user().

edit_user() can also update user roles but was still using the edit_users capability instead of the newer promote_users capability introduced in [14176].
This makes the role handling consistent with the bulk dropdown menu for role changes.

Props flixos90, johnjamesjacoby, ocean90.
Fixes #42564.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user.php

    r42343 r42855  
    15421542        $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, 'Email subject does contains HTML entities' );
    15431543    }
     1544
     1545    /**
     1546     * @ticket 42564
     1547     */
     1548    function test_edit_user_role_update() {
     1549        $_POST = $_GET = $_REQUEST = array();
     1550
     1551        $administrator = self::factory()->user->create(
     1552            array(
     1553                'role' => 'administrator',
     1554            )
     1555        );
     1556
     1557        wp_set_current_user( $administrator );
     1558
     1559        // Don't let anyone with 'promote_users' (administrator) edit their own role to something without it (subscriber).
     1560        $_POST['role']     = 'subscriber';
     1561        $_POST['email']    = 'subscriber@subscriber.test';
     1562        $_POST['nickname'] = 'subscriber';
     1563        $this->assertSame(  $administrator, edit_user( $administrator ) );
     1564
     1565        // Should still have the old role.
     1566        $this->assertSame( array( 'administrator' ), get_userdata( $administrator )->roles );
     1567
     1568        // Promote an editor to an administrator.
     1569        $editor = self::factory()->user->create(
     1570            array(
     1571                'role' => 'editor',
     1572            )
     1573        );
     1574
     1575        $_POST['role']     = 'administrator';
     1576        $_POST['email']    = 'administrator@administrator.test';
     1577        $_POST['nickname'] = 'administrator';
     1578        $this->assertSame(  $editor, edit_user( $editor ) );
     1579
     1580        // Should have the new role.
     1581        $this->assertSame( array( 'administrator' ), get_userdata( $editor )->roles );
     1582    }
    15441583}
Note: See TracChangeset for help on using the changeset viewer.