Ticket #40213: 40213.2.diff
| File 40213.2.diff, 4.2 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index c762ed4..63fb4e9 100644
a b 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 { 1363 1358 ); 1364 1359 1365 1360 $query_params['slug'] = array( 1366 'description' => __( 'Limit result set to users with a specific slug.' ), 1367 'type' => 'string', 1361 'description' => __( 'Limit result set to users with one or more specific slugs.' ), 1362 'type' => 'array', 1363 'items' => array( 1364 'type' => 'string', 1365 ), 1368 1366 ); 1369 1367 1370 1368 $query_params['roles'] = array( -
tests/phpunit/tests/rest-api/rest-users-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 0a85336..1a81e42 100644
a b 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( 580 'display_name' => 'Taco', 581 'user_login' => 'taco' 582 ) ); 583 $id2 = $this->factory->user->create( array( 584 'display_name' => 'Enchilada', 585 'user_login' => 'enchilada' 586 ) ); 587 $id3 = $this->factory->user->create( array( 588 'display_name' => 'Burrito', 589 'user_login' => 'burrito' 590 ) ); 591 $this->factory->user->create( array( 592 'display_name' => 'Hon Pizza', 593 'user_login' => 'pizza' 594 ) ); 595 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 596 $request->set_param( 'slug', array( 597 'taco', 598 'burrito', 599 'enchilada', 600 ) ); 601 $request->set_param( 'orderby', 'slug' ); 602 $request->set_param( 'order', 'asc' ); 603 $response = $this->server->dispatch( $request ); 604 $this->assertEquals( 200, $response->get_status() ); 605 $data = $response->get_data(); 606 $slugs = wp_list_pluck( $data, 'slug' ); 607 $this->assertEquals( array( 'burrito', 'enchilada', 'taco' ), $slugs ); 608 } 609 610 public function test_get_items_slug_csv_query() { 611 wp_set_current_user( self::$user ); 612 $id1 = $this->factory->user->create( array( 613 'display_name' => 'Taco', 614 'user_login' => 'taco' 615 ) ); 616 $id2 = $this->factory->user->create( array( 617 'display_name' => 'Enchilada', 618 'user_login' => 'enchilada' 619 ) ); 620 $id3 = $this->factory->user->create( array( 621 'display_name' => 'Burrito', 622 'user_login' => 'burrito' 623 ) ); 624 $this->factory->user->create( array( 625 'display_name' => 'Hon Pizza', 626 'user_login' => 'pizza' 627 ) ); 628 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 629 $request->set_param( 'slug', 'taco,burrito , enchilada'); 630 $request->set_param( 'orderby', 'slug' ); 631 $request->set_param( 'order', 'desc' ); 632 $response = $this->server->dispatch( $request ); 633 $this->assertEquals( 200, $response->get_status() ); 634 $data = $response->get_data(); 635 $slugs = wp_list_pluck( $data, 'slug' ); 636 $this->assertEquals( array( 'taco', 'enchilada', 'burrito' ), $slugs ); 637 } 638 577 639 // 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 640 public function test_get_items_roles() { 579 641 wp_set_current_user( self::$user );