Make WordPress Core


Ignore:
Timestamp:
09/25/2016 05:44:24 PM (8 years ago)
Author:
boonebgorges
Message:

Allow 'role' parameters to be passed to wp_dropdown_users().

wp_dropdown_users() contains a whitelist of function params that are
passed through to get_users(). role, role__in, and role__not_in
have now been added to this whitelist.

Props sillybean.
Fixes #38135.

File:
1 edited

Legend:

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

    r35790 r38651  
    111111        $this->assertContains( $user1->user_login, $found );
    112112    }
     113
     114    /**
     115     * @ticket 38135
     116     */
     117    public function test_role() {
     118        $u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
     119        $u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
     120
     121        $found = wp_dropdown_users( array(
     122            'echo' => false,
     123            'role' => 'author',
     124            'show' => 'user_login',
     125        ) );
     126
     127        $this->assertNotContains( $u1->user_login, $found );
     128        $this->assertContains( $u2->user_login, $found );
     129    }
     130
     131    /**
     132     * @ticket 38135
     133     */
     134    public function test_role__in() {
     135        $u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
     136        $u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
     137
     138        $found = wp_dropdown_users( array(
     139            'echo' => false,
     140            'role__in' => array( 'author', 'editor' ),
     141            'show' => 'user_login',
     142        ) );
     143
     144        $this->assertNotContains( $u1->user_login, $found );
     145        $this->assertContains( $u2->user_login, $found );
     146    }
     147
     148    /**
     149     * @ticket 38135
     150     */
     151    public function test_role__not_in() {
     152        $u1 = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
     153        $u2 = self::factory()->user->create_and_get( array( 'role' => 'author' ) );
     154
     155        $found = wp_dropdown_users( array(
     156            'echo' => false,
     157            'role__not_in' => array( 'subscriber', 'editor' ),
     158            'show' => 'user_login',
     159        ) );
     160
     161        $this->assertNotContains( $u1->user_login, $found );
     162        $this->assertContains( $u2->user_login, $found );
     163    }
    113164}
Note: See TracChangeset for help on using the changeset viewer.