Plugin_Upgrader::install()
最后更新于:2021-11-25 20:38:53
Plugin_Upgrader::install( string$package, array$args=array())Install a plugin package.
参数
- $package
-
(string) (Required) The full local path or URI of the package.
- $args
-
(array) (Optional) Other arguments for installing a plugin package.
-
‘clear_update_cache’
(bool) Whether to clear the plugin updates cache if successful. Default true.
Default value: array()
-
‘clear_update_cache’
响应
(bool|GC_Error) True if the installation was successful, false or a GC_Error otherwise.
源文件
文件: gc-admin/includes/class-plugin-upgrader.php
public function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
'overwrite_package' => false, // Do not overwrite files.
);
$parsed_args = gc_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 gc_update_plugins() knows about the new plugin.
add_action( 'upgrader_process_complete', 'gc_clean_plugins_cache', 9, 0 );
}
$this->run(
array(
'package' => $package,
'destination' => GC_PLUGIN_DIR,
'clear_destination' => $parsed_args['overwrite_package'],
'clear_working' => true,
'hook_extra' => array(
'type' => 'plugin',
'action' => 'install',
),
)
);
remove_action( 'upgrader_process_complete', 'gc_clean_plugins_cache', 9 );
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
if ( ! $this->result || is_gc_error( $this->result ) ) {
return $this->result;
}
// Force refresh of plugin update information.
gc_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;
}