wppaste
WordPress

WP_REST_Application_Passwords_Controller::get_user( WP_REST_Request $request ): WP_User|WP_Error

Since
5.6.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php:681
Gets the requested user.

Compatibility

WordPress
since 5.6.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
The request object.

Return value

WP_User|WP_Error
The WordPress user associated with the request, or a WP_Error if none found.

Performance profile

How much work a call to WP_REST_Application_Passwords_Controller::get_user() 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
Heavy

Reaches the database via get_user_by().

Scaling
Constant

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

Instructions
13–58

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 87.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
16

16 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_REST_Application_Passwords_Controller::get_user()
  • querycontent queryget_user_by()one call below WP_REST_Application_Passwords_Controller::get_user()

Further down the call graph this can also reach cache, serialize, option 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 · 20 distinct outcomes

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

WhenInstructionsCalls it makes
always13–21wp_is_application_passwords_available(), __()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && empty($user)26wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user()
wp_is_application_passwords_available() && $id !== "me" && !$id && empty($user)27wp_is_application_passwords_available(), __(), get_userdata()
wp_is_application_passwords_available() && $id === "me" && !is_user_logged_in()28wp_is_application_passwords_available(), __(), is_user_logged_in(), __()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && !->exists()29wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && !->exists()30wp_is_application_passwords_available(), __(), get_userdata(), ->exists()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && !is_multisite() && wp_is_application_passwords_available_for_user()36wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && !is_multisite() && wp_is_application_passwords_available_for_user()37wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && is_multisite() && user_can() && wp_is_application_passwords_available_for_user()43wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), user_can(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && is_multisite() && user_can() && wp_is_application_passwords_available_for_user()44wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), user_can(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && !is_multisite() && !wp_is_application_passwords_available_for_user()44wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), wp_is_application_passwords_available_for_user(), __()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && !is_multisite() && !wp_is_application_passwords_available_for_user()45wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), wp_is_application_passwords_available_for_user(), __()
8 further outcomes, up to 58 instructions
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && is_multisite() && !user_can() && !is_user_member_of_blog()45wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && is_multisite() && !user_can() && !is_user_member_of_blog()46wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && is_multisite() && !user_can() && is_user_member_of_blog() && wp_is_application_passwords_available_for_user()49wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && is_multisite() && !user_can() && is_user_member_of_blog() && wp_is_application_passwords_available_for_user()50wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog(), wp_is_application_passwords_available_for_user()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && is_multisite() && user_can() && !wp_is_application_passwords_available_for_user()51wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), user_can(), wp_is_application_passwords_available_for_user(), __()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && is_multisite() && user_can() && !wp_is_application_passwords_available_for_user()52wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), user_can(), wp_is_application_passwords_available_for_user(), __()
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && ->exists() && is_multisite() && !user_can() && is_user_member_of_blog() && !wp_is_application_passwords_available_for_user()57wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog(), wp_is_application_passwords_available_for_user(), __()
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && ->exists() && is_multisite() && !user_can() && is_user_member_of_blog() && !wp_is_application_passwords_available_for_user()58wp_is_application_passwords_available(), __(), get_userdata(), ->exists(), is_multisite(), user_can(), is_user_member_of_blog(), wp_is_application_passwords_available_for_user(), __()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 87 instructions, 13–58 executed per call, 10 branches. The work does not change between versions.

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.

Uses · 10

Used by · 16

Show all 16

Source code

	protected function get_user( $request ) {		if ( ! wp_is_application_passwords_available() ) {			return new WP_Error(				'application_passwords_disabled',				__( 'Application passwords are not available.' ),				array( 'status' => 501 )			);		} 		$error = new WP_Error(			'rest_user_invalid_id',			__( 'Invalid user ID.' ),			array( 'status' => 404 )		); 		$id = $request['user_id']; 		if ( 'me' === $id ) {			if ( ! is_user_logged_in() ) {				return new WP_Error(					'rest_not_logged_in',					__( 'You are not currently logged in.' ),					array( 'status' => 401 )				);			} 			$user = wp_get_current_user();		} else {			$id = (int) $id; 			if ( $id <= 0 ) {				return $error;			} 			$user = get_userdata( $id );		} 		if ( empty( $user ) || ! $user->exists() ) {			return $error;		} 		if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {			return $error;		} 		if ( ! wp_is_application_passwords_available_for_user( $user ) ) {			return new WP_Error(				'application_passwords_disabled_for_user',				__( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ),				array( 'status' => 501 )			);		} 		return $user;	}

Changelog

Introduced in 5.6.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.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-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.