Automattic\WooCommerce\Admin\Overrides
ThemeUpgrader::install
Install a theme package.
Method of the class: ThemeUpgrader{}
No Hooks.
Returns
true|false|WP_Error. True if the installation was successful, false or a WP_Error object otherwise.
Usage
$ThemeUpgrader = new ThemeUpgrader(); $ThemeUpgrader->install( $package, $args );
- $package(string) (required)
- The full local path or URI of the package.
- $args(array)
Other arguments for installing a theme package.
Default: empty array
- clear_update_cache(true|false)
Whether to clear the updates cache if successful.
Default: true
- clear_update_cache(true|false)
ThemeUpgrader::install() ThemeUpgrader::install code WC 10.3.6
public function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->install_strings();
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
$result = $this->run(
array(
'package' => $package,
'destination' => get_theme_root(),
'clear_destination' => false, // Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'theme',
'action' => 'install',
),
)
);
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) );
if ( $result && ! is_wp_error( $result ) ) {
// Refresh the Theme Update information.
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
}
return $result;
}