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
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
- Scaling
- Constant
- Instructions
- 13–58
- Plugin surface
- None
- Called by
- 16
Reaches the database via get_user_by().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 87.
Nothing here hands control to plugin code.
16 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_REST_Application_Passwords_Controller::get_user() - querycontent query
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13–21 | wp_is_application_passwords_available(), __() |
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && empty($user) | 26 | wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user() |
wp_is_application_passwords_available() && $id !== "me" && !$id && empty($user) | 27 | wp_is_application_passwords_available(), __(), get_userdata() |
wp_is_application_passwords_available() && $id === "me" && !is_user_logged_in() | 28 | wp_is_application_passwords_available(), __(), is_user_logged_in(), __() |
wp_is_application_passwords_available() && $id === "me" && is_user_logged_in() && !empty($user) && !->exists() | 29 | wp_is_application_passwords_available(), __(), is_user_logged_in(), wp_get_current_user(), ->exists() |
wp_is_application_passwords_available() && $id !== "me" && !$id && !empty($user) && !->exists() | 30 | wp_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() | 36 | wp_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() | 37 | wp_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() | 43 | wp_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() | 44 | wp_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() | 44 | wp_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() | 45 | wp_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() | 45 | wp_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() | 46 | wp_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() | 49 | wp_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() | 50 | wp_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() | 51 | wp_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() | 52 | wp_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() | 57 | wp_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() | 58 | wp_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
- wp_is_application_passwords_available()Checks if Application Passwords is globally available.
- __()Retrieves the translation of $text.
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- wp_get_current_user()Retrieves the current user object.
- get_userdata()Retrieves user info by user ID.
- is_multisite()Determines whether Multisite is enabled.
- user_can()Returns whether a particular user has the specified capability.
- is_user_member_of_blog()Finds out whether a user is a member of a given blog.
- wp_is_application_passwords_available_for_user()Checks if Application Passwords is available for a specific user.
- WP_Error::__construct()Initializes the error.
Used by · 16
- WP_REST_Application_Passwords_Controller::create_item()Creates an application password.
- WP_REST_Application_Passwords_Controller::create_item_permissions_check()Checks if a given request has access to create application passwords.
- WP_REST_Application_Passwords_Controller::delete_item()Deletes an application password for a user.
- WP_REST_Application_Passwords_Controller::delete_item_permissions_check()Checks if a given request has access to delete a specific application password for a user.
- WP_REST_Application_Passwords_Controller::delete_items()Deletes all application passwords for a user.
- WP_REST_Application_Passwords_Controller::delete_items_permissions_check()Checks if a given request has access to delete all application passwords for a user.
- WP_REST_Application_Passwords_Controller::do_permissions_check()Performs a permissions check for the request.
- WP_REST_Application_Passwords_Controller::get_application_password()Gets the requested application password for a user.
- WP_REST_Application_Passwords_Controller::get_current_item()Retrieves the application password being currently used for authentication of a user.
- WP_REST_Application_Passwords_Controller::get_current_item_permissions_check()Checks if a given request has access to get the currently used application password for a user.
- WP_REST_Application_Passwords_Controller::get_item_permissions_check()Checks if a given request has access to get a specific application password.
- WP_REST_Application_Passwords_Controller::get_items()Retrieves a collection of application passwords.
Show all 16
- WP_REST_Application_Passwords_Controller::get_items_permissions_check()Checks if a given request has access to get application passwords.
- WP_REST_Application_Passwords_Controller::prepare_item_for_response()Prepares the application password for the REST response.
- WP_REST_Application_Passwords_Controller::update_item()Updates an application password.
- WP_REST_Application_Passwords_Controller::update_item_permissions_check()Checks if a given request has access to update application passwords.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.