Ticket #40213: 40213.1.diff
| File 40213.1.diff, 4.5 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index c762ed41d7..c118a8e436 100644
class WP_REST_Users_Controller extends WP_REST_Controller { 221 221 'per_page' => 'number', 222 222 'search' => 'search', 223 223 'roles' => 'role__in', 224 'slug' => 'nicename__in' 224 225 ); 225 226 226 227 $prepared_args = array(); … … class WP_REST_Users_Controller extends WP_REST_Controller { 261 262 if ( ! empty( $prepared_args['search'] ) ) { 262 263 $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; 263 264 } 264 265 if ( isset( $registered['slug'] ) && ! empty( $request['slug'] ) ) {266 $prepared_args['search'] = $request['slug'];267 $prepared_args['search_columns'] = array( 'user_nicename' );268 }269 270 265 /** 271 266 * Filters WP_User_Query arguments when querying users via the REST API. 272 267 * … … class WP_REST_Users_Controller extends WP_REST_Controller { 278 273 * @param WP_REST_Request $request The current request. 279 274 */ 280 275 $prepared_args = apply_filters( 'rest_user_query', $prepared_args, $request ); 281 282 276 $query = new WP_User_Query( $prepared_args ); 283 277 284 278 $users = array(); … … class WP_REST_Users_Controller extends WP_REST_Controller { 1363 1357 ); 1364 1358 1365 1359 $query_params['slug'] = array( 1366 'description' => __( 'Limit result set to users with a specific slug.' ), 1367 'type' => 'string', 1360 'description' => __( 'Limit result set to users with a specific slug.' ), 1361 'type' => 'array', 1362 'items' => array( 1363 'type' => 'string', 1364 ) 1368 1365 ); 1369 1366 1370 1367 $query_params['roles'] = array( -
tests/phpunit/tests/rest-api/rest-users-controller.php
diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php index 0a85336155..7931ac5760 100644
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 574 574 $this->assertEquals( $id2, $data[0]['id'] ); 575 575 } 576 576 577 public function test_get_items_slug_array_query() { 578 wp_set_current_user( self::$user ); 579 $id1 = $this->factory->user->create( array( 'display_name' => 'Taco', 'user_login' => 'taco' ) ); 580 $id2 = $this->factory->user->create( array( 'display_name' => 'Enchilada', 'user_login' => 'enchilada' ) ); 581 $id3 = $this->factory->user->create( array( 'display_name' => 'Burrito', 'user_login' => 'burrito' ) ); 582 $this->factory->user->create( array( 'display_name' => 'Hon Pizza', 'user_login' => 'pizza' ) ); 583 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 584 $request->set_param( 'slug', array( 585 'taco', 586 'burrito', 587 'enchilada', 588 ) ); 589 $request->set_param( 'orderby', 'slug' ); 590 $request->set_param( 'order', 'desc' ); 591 $response = $this->server->dispatch( $request ); 592 $this->assertEquals( 200, $response->get_status() ); 593 $data = $response->get_data(); 594 $this->assertEquals( 3, count( $data ) ); 595 $this->assertEquals( $id1, $data[0]['id'] ); 596 $this->assertEquals( $id2, $data[1]['id'] ); 597 $this->assertEquals( $id3, $data[2]['id'] ); 598 } 599 600 public function test_get_items_csv_array_query() { 601 wp_set_current_user( self::$user ); 602 $id1 = $this->factory->user->create( array( 'display_name' => 'Taco', 'user_login' => 'taco' ) ); 603 $id2 = $this->factory->user->create( array( 'display_name' => 'Enchilada', 'user_login' => 'enchilada' ) ); 604 $id3 = $this->factory->user->create( array( 'display_name' => 'Burrito', 'user_login' => 'burrito' ) ); 605 $this->factory->user->create( array( 'display_name' => 'Hon Pizza', 'user_login' => 'pizza' ) ); 606 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 607 $request->set_param( 'slug', 'taco, burrito, enchilada'); 608 $request->set_param( 'orderby', 'slug' ); 609 $request->set_param( 'order', 'desc' ); 610 $response = $this->server->dispatch( $request ); 611 $this->assertEquals( 200, $response->get_status() ); 612 $data = $response->get_data(); 613 $this->assertEquals( 3, count( $data ) ); 614 $this->assertEquals( $id1, $data[0]['id'] ); 615 $this->assertEquals( $id2, $data[1]['id'] ); 616 $this->assertEquals( $id3, $data[2]['id'] ); 617 } 618 577 619 // Note: Do not test using editor role as there is an editor role created in testing and it makes it hard to test this functionality. 578 620 public function test_get_items_roles() { 579 621 wp_set_current_user( self::$user );