REST API: Allow fetching multiple users at once via the slug parameter.

This matches similar changes previously made for posts (#38579) and terms (#40027).

Props curdin, MatheusGimenez.
Fixes #40213.


git-svn-id: https://develop.svn.wordpress.org/trunk@40378 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
James Nylen
2017-04-05 22:24:24 +00:00
parent 66b4bb9809
commit a7b3612f2a
3 changed files with 75 additions and 12 deletions

View File

@@ -221,6 +221,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
'per_page' => 'number',
'search' => 'search',
'roles' => 'role__in',
'slug' => 'nicename__in',
);
$prepared_args = array();
@@ -261,12 +262,6 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
if ( ! empty( $prepared_args['search'] ) ) {
$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
}
if ( isset( $registered['slug'] ) && ! empty( $request['slug'] ) ) {
$prepared_args['search'] = $request['slug'];
$prepared_args['search_columns'] = array( 'user_nicename' );
}
/**
* Filters WP_User_Query arguments when querying users via the REST API.
*
@@ -1363,8 +1358,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
);
$query_params['slug'] = array(
'description' => __( 'Limit result set to users with a specific slug.' ),
'type' => 'string',
'description' => __( 'Limit result set to users with one or more specific slugs.' ),
'type' => 'array',
'items' => array(
'type' => 'string',
),
);
$query_params['roles'] = array(