Skip to content

Commit

Permalink
Adds the ability to filter users in the WPCOM_JSON_API_List_Users_End…
Browse files Browse the repository at this point in the history
…point endpoint by capability (#36893)

* Adds the ability to filter users in the WPCOM_JSON_API_List_Users_Endpoint endpoint by capability

* Update doc

* Rename capabilities to capability and make it inclusive
  • Loading branch information
TimBroddin authored Apr 16, 2024
1 parent dbcabbb commit 7948dc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Adds the ability to filter users in the WPCOM_JSON_API_List_Users_Endpoint endpoint by capability
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'search' => '(string) Find matching users.',
'search_columns' => "(array) Specify which columns to check for matching users. Can be any of 'ID', 'user_login', 'user_email', 'user_url', 'user_nicename', and 'display_name'. Only works when combined with `search` parameter.",
'role' => '(string) Specify a specific user role to fetch.',
'capability' => '(string) Specify a specific capability to fetch. You can specify multiple by comma separating them, in which case the user needs to match all capabilities provided.',
),

'response_format' => array(
Expand Down Expand Up @@ -159,6 +160,10 @@ public function callback( $path = '', $blog_id = 0 ) {
$query['role'] = $args['role'];
}

if ( ! empty( $args['capability'] ) ) {
$query['capability'] = $args['capability'];
}

$user_query = new WP_User_Query( $query );

remove_filter( 'user_search_columns', array( $this, 'api_user_override_search_columns' ) );
Expand Down

0 comments on commit 7948dc9

Please sign in to comment.