wppaste
WordPress

WP_REST_Plugins_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error

Since
5.5.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php:273
Uploads a plugin and optionally activates it.

Compatibility

WordPress
since 5.5.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_Plugins_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
Expensive

Reaches an outbound HTTP request via wp_remote_get().

Scaling
Constant

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

Instructions
6

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

Plugin surface
1 hook

Third-party callbacks on 'plugins_update_check_locales' 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
  • httpoutbound HTTP requestwp_remote_get()one call below WP_REST_Plugins_Controller::create_item()

Further down the call graph this can also reach query, option, 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_Plugins_Controller::create_item() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always6none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev245615
8.5245615
8.424561510 fewer instructions than PHP 8.3
8.3255915
8.2255915
8.125591512 more instructions than PHP 7.4
7.424324–16915

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_Plugins_Controller::create_item() runs, in this order:

  1. apply_filters( plugins_update_check_locales )filterline 381 (+108 into the body)

    Filters the locales requested for plugin translations.

Uses · 16

Show all 16

Source code

	public function create_item( $request ) {		global $wp_filesystem; 		require_once ABSPATH . 'wp-admin/includes/file.php';		require_once ABSPATH . 'wp-admin/includes/plugin.php';		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';		require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 		$slug = $request['slug']; 		// Verify filesystem is accessible first.		$filesystem_available = $this->is_filesystem_available();		if ( is_wp_error( $filesystem_available ) ) {			return $filesystem_available;		} 		$api = plugins_api(			'plugin_information',			array(				'slug'   => $slug,				'fields' => array(					'sections'       => false,					'language_packs' => true,				),			)		); 		if ( is_wp_error( $api ) ) {			if ( str_contains( $api->get_error_message(), 'Plugin not found.' ) ) {				$api->add_data( array( 'status' => 404 ) );			} else {				$api->add_data( array( 'status' => 500 ) );			} 			return $api;		} 		$skin     = new WP_Ajax_Upgrader_Skin();		$upgrader = new Plugin_Upgrader( $skin ); 		$result = $upgrader->install( $api->download_link ); 		if ( is_wp_error( $result ) ) {			$result->add_data( array( 'status' => 500 ) ); 			return $result;		} 		// This should be the same as $result above.		if ( is_wp_error( $skin->result ) ) {			$skin->result->add_data( array( 'status' => 500 ) ); 			return $skin->result;		} 		if ( $skin->get_errors()->has_errors() ) {			$error = $skin->get_errors();			$error->add_data( array( 'status' => 500 ) ); 			return $error;		} 		if ( is_null( $result ) ) {			// Pass through the error from WP_Filesystem if one was raised.			if ( $wp_filesystem instanceof WP_Filesystem_Base				&& is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors()			) {				return new WP_Error(					'unable_to_connect_to_filesystem',					$wp_filesystem->errors->get_error_message(),					array( 'status' => 500 )				);			} 			return new WP_Error(				'unable_to_connect_to_filesystem',				__( 'Unable to connect to the filesystem. Please confirm your credentials.' ),				array( 'status' => 500 )			);		}

Changelog

Introduced in 5.5.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.9.7 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-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.