wppaste
WordPress

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
Creates an application password.

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

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
10–86

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

Plugin surface
1 hook

Third-party callbacks on 'rest_after_insert_application_password' 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 callbacksdo_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.

WhenInstructionsCalls it makes
is_wp_error()10->get_user(), is_wp_error()
always18->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error()
always33->get_user(), is_wp_error(), ->prepare_item_for_database(), is_wp_error(), wp_slash(), ::WP_Application_Passwords(), is_wp_error()
always58->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

PHPCompiledExecutedBranchesNotes
8.6-dev9010–864
8.59010–864
8.49010–864
8.39010–864
8.29010–864
8.19010–8641 fewer instruction than PHP 7.4
7.49110–874

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:

  1. 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

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.

  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 7.0.4 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.