WP_REST_Application_Passwords_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error
- Since
- 5.6.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php:235
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- 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_Application_Passwords_Controller::create_item() 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
- Scaling
- Constant
- Instructions
- 10–86
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
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 90.
Third-party callbacks on 'rest_after_insert_application_password' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly
What one call costs · 5 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::create_item() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 10 | ->get_user(), is_wp_error() |
| always | 18 | ->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error() |
| always | 33 | ->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), wp_slash(), ::WP_Application_Passwords(), is_wp_error() |
| always | 58 | ->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), wp_slash(), ::WP_Application_Passwords(), is_wp_error(), ::WP_Application_Passwords(), ::WP_Application_Passwords(), ->update_additional_fields_for_object(), is_wp_error() |
!is_wp_error() | 86 | ->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), wp_slash(), ::WP_Application_Passwords(), is_wp_error(), ::WP_Application_Passwords(), ::WP_Application_Passwords(), ->update_additional_fields_for_object(), is_wp_error(), do_action(), ->set_param(), ->prepare_item_for_response(), ->set_status(), ->get_links(), ->header() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 90 | 10–86 | 4 | |
| 8.5 | 90 | 10–86 | 4 | |
| 8.4 | 90 | 10–86 | 4 | |
| 8.3 | 90 | 10–86 | 4 | |
| 8.2 | 90 | 10–86 | 4 | |
| 8.1 | 90 | 10–86 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 91 | 10–87 | 4 |
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_Application_Passwords_Controller::create_item() runs, in this order:
- do_action( rest_after_insert_application_password )actionline 273 (+38 into the body)
Fires after a single application password is completely created or updated via the REST API.
Uses · 10
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_slash()Adds slashes to a string or recursively adds slashes to strings within an array.
- do_action()Calls the callback functions that have been added to an action hook.
- WP_REST_Application_Passwords_Controller::get_user()Gets the requested user.
- WP_REST_Application_Passwords_Controller::prepare_item_for_database()Prepares an application password for a create or update operation.
- WP_Application_Passwords::create_new_application_password()Creates a new application password.
- WP_Application_Passwords::get_user_application_password()Gets a user's application password with the given UUID.
- WP_Application_Passwords::chunk_password()Sanitizes and then splits a password into smaller chunks.
- WP_REST_Application_Passwords_Controller::update_additional_fields_for_object()
- WP_REST_Application_Passwords_Controller::prepare_item_for_response()Prepares the application password for the REST response.
Source code
public function create_item( $request ) { $user = $this->get_user( $request ); if ( is_wp_error( $user ) ) { return $user; } $prepared = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared ) ) { return $prepared; } $created = WP_Application_Passwords::create_new_application_password( $user->ID, wp_slash( (array) $prepared ) ); if ( is_wp_error( $created ) ) { return $created; } $password = $created[0]; $item = WP_Application_Passwords::get_user_application_password( $user->ID, $created[1]['uuid'] ); $item['new_password'] = WP_Application_Passwords::chunk_password( $password ); $fields_update = $this->update_additional_fields_for_object( $item, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } /** * Fires after a single application password is completely created or updated via the REST API. * * @since 5.6.0 * * @param array $item Inserted or updated password item. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating an application password, false when updating. */ do_action( 'rest_after_insert_application_password', $item, $request, true ); $request->set_param( 'context', 'edit' ); $response = $this->prepare_item_for_response( $item, $request ); $response->set_status( 201 ); $response->header( 'Location', $response->get_links()['self'][0]['href'] ); return $response; }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.