Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2000 from WP-API/1970-exclude-users
Browse files Browse the repository at this point in the history
Add `exclude` param to `GET /wp/v2/users`
  • Loading branch information
rachelbaker committed Jan 12, 2016
2 parents 366483d + f16fed1 commit 14709f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/endpoints/class-wp-rest-users-controller.php
Expand Up @@ -80,6 +80,7 @@ public function register_routes() {
public function get_items( $request ) {

$prepared_args = array();
$prepared_args['exclude'] = $request['exclude'];
$prepared_args['include'] = $request['include'];
$prepared_args['order'] = $request['order'];
$prepared_args['number'] = $request['per_page'];
Expand Down
33 changes: 33 additions & 0 deletions tests/test-rest-users-controller.php
Expand Up @@ -50,6 +50,23 @@ public function test_context_param() {
$this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
}

public function test_registered_query_params() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$keys = array_keys( $data['endpoints'][0]['args'] );
sort( $keys );
$this->assertEquals( array(
'context',
'include',
'order',
'orderby',
'page',
'per_page',
'search',
), $keys );
}

public function test_get_items() {
wp_set_current_user( $this->user );

Expand Down Expand Up @@ -226,6 +243,22 @@ public function test_get_items_include_query() {
$this->assertEquals( $id3, $data[0]['id'] );
}

public function test_get_items_exclude_query() {
wp_set_current_user( $this->user );
$id1 = $this->factory->user->create();
$id2 = $this->factory->user->create();
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
$this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
$request->set_param( 'exclude', array( $id2 ) );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ) ) );
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ) ) );
}

public function test_get_items_search() {
wp_set_current_user( $this->user );
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
Expand Down

0 comments on commit 14709f9

Please sign in to comment.