wppaste
WordPress

WP_REST_Users_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error

Since
4.7.0, 6.8.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:265
Retrieves all users.

Compatibility

WordPress
since 6.8.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$requestWP_REST_Request
Full details about the request.

Return value

WP_REST_Response|WP_Error
Response object on success, or WP_Error object on failure.

Performance profile

How much work a call to WP_REST_Users_Controller::get_items() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
4

Executed per call on PHP 8.5. The body compiles to 264.

Plugin surface
1 hook

Third-party callbacks on 'rest_user_query' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach option, query, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Users_Controller::get_items() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always4none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev2624282 fewer instructions than PHP 8.5
8.5264428
8.42644282 fewer instructions than PHP 8.3
8.3266428
8.2266428
8.12664282 more instructions than PHP 7.4
7.4264105–20128

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_REST_Users_Controller::get_items() runs, in this order:

  1. apply_filters( rest_user_query )filterline 374 (+109 into the body)

    Filters WP_User_Query arguments when querying users via the REST API.

Uses · 12

Source code

	public function get_items( $request ) { 		// Retrieve the list of registered collection query parameters.		$registered = $this->get_collection_params(); 		/*		 * This array defines mappings between public API query parameters whose		 * values are accepted as-passed, and their internal WP_Query parameter		 * name equivalents (some are the same). Only values which are also		 * present in $registered will be set.		 */		$parameter_mappings = array(			'exclude'      => 'exclude',			'include'      => 'include',			'order'        => 'order',			'per_page'     => 'number',			'search'       => 'search',			'roles'        => 'role__in',			'capabilities' => 'capability__in',			'slug'         => 'nicename__in',		); 		$prepared_args = array(); 		/*		 * For each known parameter which is both registered and present in the request,		 * set the parameter's value on the query $prepared_args.		 */		foreach ( $parameter_mappings as $api_param => $wp_param ) {			if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) {				$prepared_args[ $wp_param ] = $request[ $api_param ];			}		} 		if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) {			$prepared_args['offset'] = $request['offset'];		} else {			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];		} 		if ( isset( $registered['orderby'] ) ) {			$orderby_possibles        = array(				'id'              => 'ID',				'include'         => 'include',				'name'            => 'display_name',				'registered_date' => 'registered',				'slug'            => 'user_nicename',				'include_slugs'   => 'nicename__in',				'email'           => 'user_email',				'url'             => 'user_url',			);			$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];		} 		if ( isset( $registered['who'] ) && ! empty( $request['who'] ) && 'authors' === $request['who'] ) {			$prepared_args['who'] = 'authors';		} elseif ( ! current_user_can( 'list_users' ) ) {			$prepared_args['has_published_posts'] = get_post_types( array( 'show_in_rest' => true ), 'names' );		} 		if ( ! empty( $request['has_published_posts'] ) ) {			$prepared_args['has_published_posts'] = ( true === $request['has_published_posts'] )				? get_post_types( array( 'show_in_rest' => true ), 'names' )				: (array) $request['has_published_posts'];		} 		if ( ! empty( $prepared_args['search'] ) ) {			if ( ! current_user_can( 'list_users' ) ) {				$prepared_args['search_columns'] = array( 'ID', 'user_login', 'user_nicename', 'display_name' );			}			$search_columns         = $request->get_param( 'search_columns' );			$valid_columns          = isset( $prepared_args['search_columns'] )				? $prepared_args['search_columns']				: array( 'ID', 'user_login', 'user_nicename', 'user_email', 'display_name' );			$search_columns_mapping = array(				'id'       => 'ID',				'username' => 'user_login',				'slug'     => 'user_nicename',				'email'    => 'user_email',				'name'     => 'display_name',

Changelog

Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.0
Added support for the search_columns query param.from the docblock
4.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.