PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | json-endpoints/class.wpcom-json-api-list-users-endpoint.php +21 -4 13.5.216.3-a.1 View file →
@@ -1,6 +1,10 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit( 0 );
5 +}
6 +
3 7 /**
4 8 * List users endpoint.
5 9 */
6 10 new WPCOM_JSON_API_List_Users_Endpoint(
@@ -13,8 +17,10 @@
13 17 'path' => '/sites/%s/users',
14 18 'path_labels' => array(
15 19 '$site' => '(int|string) Site ID or domain',
16 20 ),
21 + 'rest_route' => '/users',
22 + 'rest_min_jp_version' => '15.9',
17 23
18 24 'query_parameters' => array(
19 25 'number' => '(int=20) Limit the total number of authors returned.',
20 26 'offset' => '(int=0) The first n authors to be skipped in the returned array.',
@@ -37,9 +43,9 @@
37 43 'type' => "(string) Specify the post type to query authors for. Only works when combined with the `authors_only` flag. Defaults to 'post'. Post types besides post and page need to be whitelisted using the <code>rest_api_allowed_post_types</code> filter.",
38 44 'search' => '(string) Find matching users.',
39 45 '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.",
40 46 'role' => '(string) Specify a specific user role to fetch.',
41 - '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.',
47 + '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.',
42 48 ),
43 49
44 50 'response_format' => array(
45 51 'found' => '(int) The total number of authors found that match the request (ignoring limits and offsets).',
@@ -81,8 +87,10 @@
81 87 /**
82 88 * List users endpoint class.
83 89 *
84 90 * /sites/%s/users/ -> $blog_id
91 + *
92 + * @phan-constructor-used-for-side-effects
85 93 */
86 94 class WPCOM_JSON_API_List_Users_Endpoint extends WPCOM_JSON_API_Endpoint {
87 95
88 96 /**
@@ -95,8 +103,15 @@
95 103 'users' => '(array:author) Array of user objects',
96 104 );
97 105
98 106 /**
107 + * Columns in which to search for a user match.
108 + *
109 + * @var array
110 + */
111 + public $search_columns;
112 +
113 + /**
99 114 * API callback.
100 115 *
101 116 * @param string $path - the path.
102 117 * @param string $blog_id - the blog ID.
@@ -168,9 +183,9 @@
168 183
169 184 remove_filter( 'user_search_columns', array( $this, 'api_user_override_search_columns' ) );
170 185
171 186 $is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM;
172 - $include_viewers = (bool) isset( $args['include_viewers'] ) && $args['include_viewers'] && $is_wpcom;
187 + $include_viewers = isset( $args['include_viewers'] ) && $args['include_viewers'] && $is_wpcom;
173 188
174 189 $page = ( (int) ( $args['offset'] / $args['number'] ) ) + 1;
175 190 $viewers = $include_viewers ? get_private_blog_users(
176 191 $blog_id,
@@ -180,16 +195,18 @@
180 195 )
181 196 ) : array();
182 197 $viewers = array_map( array( $this, 'get_author' ), $viewers );
183 198
184 - // we restrict search field to name when include_viewers is true.
199 + // When include_viewers is true, search by username or email.
185 200 if ( $include_viewers && ! empty( $args['search'] ) ) {
186 201 $viewers = array_filter(
187 202 $viewers,
188 203 function ( $viewer ) use ( $args ) {
204 + // Convert to WP_User so expected fields are available.
205 + $wp_viewer = new WP_User( $viewer->ID );
189 206 // remove special database search characters from search term
190 207 $search_term = str_replace( '*', '', $args['search'] );
191 - return strpos( $viewer->name, $search_term ) !== false;
208 + return ( str_contains( $wp_viewer->user_login, $search_term ) || str_contains( $wp_viewer->user_email, $search_term ) || str_contains( $wp_viewer->display_name, $search_term ) );
192 209 }
193 210 );
194 211 }
195 212