Changeset 40426 for branches/4.7
- Timestamp:
- 04/14/2017 08:46:22 AM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r40111 r40426 221 221 'search' => 'search', 222 222 'roles' => 'role__in', 223 'slug' => 'nicename__in', 223 224 ); 224 225 … … 261 262 $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; 262 263 } 263 264 if ( isset( $registered['slug'] ) && ! empty( $request['slug'] ) ) {265 $prepared_args['search'] = $request['slug'];266 $prepared_args['search_columns'] = array( 'user_nicename' );267 }268 269 264 /** 270 265 * Filters WP_User_Query arguments when querying users via the REST API. … … 1362 1357 $query_params['slug'] = array( 1363 1358 'description' => __( 'Limit result set to users with a specific slug.' ), 1364 'type' => 'string', 1359 'type' => 'array', 1360 'items' => array( 1361 'type' => 'string', 1362 ), 1365 1363 ); 1366 1364 -
branches/4.7/tests/phpunit/tests/rest-api/rest-users-controller.php
r40111 r40426 583 583 $this->assertEquals( 1, count( $data ) ); 584 584 $this->assertEquals( $id2, $data[0]['id'] ); 585 } 586 587 public function test_get_items_slug_array_query() { 588 wp_set_current_user( self::$user ); 589 $id1 = $this->factory->user->create( array( 590 'display_name' => 'Taco', 591 'user_login' => 'taco' 592 ) ); 593 $id2 = $this->factory->user->create( array( 594 'display_name' => 'Enchilada', 595 'user_login' => 'enchilada' 596 ) ); 597 $id3 = $this->factory->user->create( array( 598 'display_name' => 'Burrito', 599 'user_login' => 'burrito' 600 ) ); 601 $this->factory->user->create( array( 602 'display_name' => 'Hon Pizza', 603 'user_login' => 'pizza' 604 ) ); 605 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 606 $request->set_param( 'slug', array( 607 'taco', 608 'burrito', 609 'enchilada', 610 ) ); 611 $request->set_param( 'orderby', 'slug' ); 612 $request->set_param( 'order', 'asc' ); 613 $response = $this->server->dispatch( $request ); 614 $this->assertEquals( 200, $response->get_status() ); 615 $data = $response->get_data(); 616 $slugs = wp_list_pluck( $data, 'slug' ); 617 $this->assertEquals( array( 'burrito', 'enchilada', 'taco' ), $slugs ); 618 } 619 620 public function test_get_items_slug_csv_query() { 621 wp_set_current_user( self::$user ); 622 $id1 = $this->factory->user->create( array( 623 'display_name' => 'Taco', 624 'user_login' => 'taco' 625 ) ); 626 $id2 = $this->factory->user->create( array( 627 'display_name' => 'Enchilada', 628 'user_login' => 'enchilada' 629 ) ); 630 $id3 = $this->factory->user->create( array( 631 'display_name' => 'Burrito', 632 'user_login' => 'burrito' 633 ) ); 634 $this->factory->user->create( array( 635 'display_name' => 'Hon Pizza', 636 'user_login' => 'pizza' 637 ) ); 638 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 639 $request->set_param( 'slug', 'taco,burrito , enchilada'); 640 $request->set_param( 'orderby', 'slug' ); 641 $request->set_param( 'order', 'desc' ); 642 $response = $this->server->dispatch( $request ); 643 $this->assertEquals( 200, $response->get_status() ); 644 $data = $response->get_data(); 645 $slugs = wp_list_pluck( $data, 'slug' ); 646 $this->assertEquals( array( 'taco', 'enchilada', 'burrito' ), $slugs ); 585 647 } 586 648 -
branches/4.7/tests/qunit/fixtures/wp-api-generated.js
r40336 r40426 2440 2440 "required": false, 2441 2441 "description": "Limit result set to users with a specific slug.", 2442 "type": "string" 2442 "type": "array", 2443 "items": { 2444 "type": "string" 2445 } 2443 2446 }, 2444 2447 "roles": {
Note: See TracChangeset
for help on using the changeset viewer.