WordPress at Your Fingertips
function is not described

Plugin_Upgrader::install() public WP 2.8.0

Install a plugin package.

{} It's a method of the class: Plugin_Upgrader{}

Hooks from the method
Return

true|false|WP_Error. True if the installation was successful, false or a WP_Error otherwise.

Usage

$Plugin_Upgrader = new Plugin_Upgrader();
$Plugin_Upgrader->install( $package, $args );
$package(string) (required)
The full local path or URI of the package.
$args(array)

Other arguments for installing a plugin package.

Default: empty array

  • clear_update_cache(true|false)
    Whether to clear the plugin updates cache if successful.
    Default: true

Changelog

Since 2.8.0 Introduced.
Since 3.7.0 The $args parameter was added, making clearing the plugin update cache optional.

Code of Plugin_Upgrader::install() WP 5.8

<?php
public function install( $package, $args = array() ) {
	$defaults    = array(
		'clear_update_cache' => true,
		'overwrite_package'  => false, // Do not overwrite files.
	);
	$parsed_args = wp_parse_args( $args, $defaults );

	$this->init();
	$this->install_strings();

	add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );

	if ( $parsed_args['clear_update_cache'] ) {
		// Clear cache so wp_update_plugins() knows about the new plugin.
		add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
	}

	$this->run(
		array(
			'package'           => $package,
			'destination'       => WP_PLUGIN_DIR,
			'clear_destination' => $parsed_args['overwrite_package'],
			'clear_working'     => true,
			'hook_extra'        => array(
				'type'   => 'plugin',
				'action' => 'install',
			),
		)
	);

	remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
	remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );

	if ( ! $this->result || is_wp_error( $this->result ) ) {
		return $this->result;
	}

	// Force refresh of plugin update information.
	wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );

	if ( $parsed_args['overwrite_package'] ) {
		/**
		 * Fires when the upgrader has successfully overwritten a currently installed
		 * plugin or theme with an uploaded zip package.
		 *
		 * @since 5.5.0
		 *
		 * @param string  $package      The package file.
		 * @param array   $data         The new plugin or theme data.
		 * @param string  $package_type The package type ('plugin' or 'theme').
		 */
		do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
	}

	return true;
}