Theme_Upgrader::install( string $package, array $args = array() ): bool|WP_Error
- Since
- 2.8.0, 3.7.0
- Source
wp-admin/includes/class-theme-upgrader.php:230
Compatibility
- WordPress
- since 3.7.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
$packagestring- The full local path or URI of the package.
$argsarrayoptional- Other arguments for installing a theme package. Default empty array.Default:
array()$clear_update_cachebooldefault: trueWhether to clear the updates cache if successful.
Return value
bool|WP_Error- True if the installation was successful, false or a WP_Error object otherwise.
Performance profile
How much work a call to Theme_Upgrader::install() 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
- Scaling
- Constant
- Instructions
- 64–90
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.
Third-party callbacks on 'upgrader_overwrote_package' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly
Further down the call graph this can also reach option, cache, transient, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost Theme_Upgrader::install() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$parsed_args | 64 | wp_parse_args(), ->init(), ->install_strings(), get_theme_root(), package(), remove_action() |
!$parsed_args && is_wp_error() | 70 | wp_parse_args(), ->init(), ->install_strings(), get_theme_root(), package(), remove_action(), is_wp_error() |
$parsed_args | 70 | wp_parse_args(), ->init(), ->install_strings(), add_action(), get_theme_root(), package(), remove_action() |
!$parsed_args && !is_wp_error() | 76 | wp_parse_args(), ->init(), ->install_strings(), get_theme_root(), package(), remove_action(), is_wp_error(), wp_clean_themes_cache() |
$parsed_args && is_wp_error() | 76 | wp_parse_args(), ->init(), ->install_strings(), add_action(), get_theme_root(), package(), remove_action(), is_wp_error() |
!is_wp_error() | 82 | wp_parse_args(), ->init(), ->install_strings(), add_action(), get_theme_root(), package(), remove_action(), is_wp_error(), wp_clean_themes_cache() |
!is_wp_error() | 84 | wp_parse_args(), ->init(), ->install_strings(), get_theme_root(), package(), remove_action(), is_wp_error(), wp_clean_themes_cache(), do_action() |
$parsed_args && !is_wp_error() | 90 | wp_parse_args(), ->init(), ->install_strings(), add_action(), get_theme_root(), package(), remove_action(), is_wp_error(), wp_clean_themes_cache(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 92 instructions, 64–90 executed per call, 4 branches. The work does not change between versions.
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 Theme_Upgrader::install() runs, in this order:
- do_action( upgrader_overwrote_package )actionline 274 (+44 into the body)
Fires when the upgrader has successfully overwritten a currently installed plugin or theme with an uploaded zip package.
Uses · 12
- wp_parse_args()Merges user defined arguments into defaults array.
- add_filter()Adds a callback function to a filter hook.
- add_action()Adds a callback function to an action hook.
- get_theme_root()Retrieves path to themes directory.
- remove_action()Removes a callback function from an action hook.
- remove_filter()Removes a callback function from a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_clean_themes_cache()Clears the cache held by get_theme_roots() and WP_Theme.
- do_action()Calls the callback functions that have been added to an action hook.
- Theme_Upgrader::init()
- Theme_Upgrader::install_strings()Initializes the installation strings.
- Theme_Upgrader::run()
Source code
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' ) ); 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 ); } $this->run( array( 'package' => $package, 'destination' => get_theme_root(), 'clear_destination' => $parsed_args['overwrite_package'], '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 ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; } // Refresh the Theme Update information. wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); if ( $parsed_args['overwrite_package'] ) { /** This action is documented in wp-admin/includes/class-plugin-upgrader.php */ do_action( 'upgrader_overwrote_package', $package, $this->new_theme_data, 'theme' ); } return true; }Changelog
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$args parameter was added, making clearing the update cache optional.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-admin/includes/class-theme-upgrader.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.