From 7948dc96197860db780a561d680c56320912453a Mon Sep 17 00:00:00 2001 From: Tim Broddin Date: Tue, 16 Apr 2024 12:56:32 +0200 Subject: [PATCH] Adds the ability to filter users in the WPCOM_JSON_API_List_Users_Endpoint 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 --- .../changelog/add-list-users-endpoint-capabilities-filter | 4 ++++ .../class.wpcom-json-api-list-users-endpoint.php | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/add-list-users-endpoint-capabilities-filter diff --git a/projects/plugins/jetpack/changelog/add-list-users-endpoint-capabilities-filter b/projects/plugins/jetpack/changelog/add-list-users-endpoint-capabilities-filter new file mode 100644 index 0000000000000..e8fe16a15ec01 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-list-users-endpoint-capabilities-filter @@ -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 diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php index 3dc7291a60a28..7265c6d02330a 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php @@ -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( @@ -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' ) );