Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r40106 r40378 222 222 'search' => 'search', 223 223 'roles' => 'role__in', 224 'slug' => 'nicename__in', 224 225 ); 225 226 … … 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. … … 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 -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r40106 r40378 573 573 $this->assertEquals( 1, count( $data ) ); 574 574 $this->assertEquals( $id2, $data[0]['id'] ); 575 } 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 ); 575 637 } 576 638 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r40376 r40378 1990 1990 "slug": { 1991 1991 "required": false, 1992 "description": "Limit result set to terms with a specific slug.",1992 "description": "Limit result set to terms with one or more specific slugs.", 1993 1993 "type": "array", 1994 1994 "items": { … … 2228 2228 "slug": { 2229 2229 "required": false, 2230 "description": "Limit result set to terms with a specific slug.",2230 "description": "Limit result set to terms with one or more specific slugs.", 2231 2231 "type": "array", 2232 2232 "items": { … … 2445 2445 "slug": { 2446 2446 "required": false, 2447 "description": "Limit result set to users with a specific slug.", 2448 "type": "string" 2447 "description": "Limit result set to users with one or more specific slugs.", 2448 "type": "array", 2449 "items": { 2450 "type": "string" 2451 } 2449 2452 }, 2450 2453 "roles": {
Note: See TracChangeset
for help on using the changeset viewer.