WP_Upgrader::move_to_temp_backup_dir( string[] $args ): bool|WP_Error
- Since
- 6.3.0
- Source
wp-admin/includes/class-wp-upgrader.php:1123
Compatibility
- WordPress
- since 6.3.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
$argsstring[]- Array of data for the temporary backup.
$slugstringPlugin or theme slug.$srcstringPath to the root directory for plugins or themes.$dirstringDestination subdirectory name. Accepts 'plugins' or 'themes'.
Return value
bool|WP_Error- True on success, false on early exit, otherwise WP_Error.
Performance profile
How much work a call to WP_Upgrader::move_to_temp_backup_dir() 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
- Heavy
- Scaling
- Constant
- Instructions
- 5–84
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->delete().
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 103.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
->delete()called directly - hookthird-party callbacks
do_action()one call below WP_Upgrader::move_to_temp_backup_dir()
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 · 10 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Upgrader::move_to_temp_backup_dir() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–12 | none |
!empty($args) && !->wp_content_dir() | 22 | ->wp_content_dir() |
!empty($args) && ->wp_content_dir() && !->mkdir() | 42 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir() |
!empty($args) && ->wp_content_dir() && !->is_dir() && !->mkdir() | 47 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir(), ->mkdir() |
!empty($args) && ->wp_content_dir() | 58–65 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), move_dir(), is_wp_error() |
!empty($args) && ->wp_content_dir() && ->is_dir() | 62–69 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), ->delete(), move_dir(), is_wp_error() |
!empty($args) && ->wp_content_dir() && ->mkdir() | 68–75 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), move_dir(), is_wp_error() |
!empty($args) && ->wp_content_dir() && ->mkdir() | 72–79 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), ->delete(), move_dir(), is_wp_error() |
!empty($args) && ->wp_content_dir() && !->is_dir() && ->mkdir() | 73–80 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir(), ->mkdir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), move_dir(), is_wp_error() |
!empty($args) && ->wp_content_dir() && ->mkdir() | 77–84 | ->wp_content_dir(), ->wp_content_dir(), ->is_dir(), ->is_dir(), ->mkdir(), ->mkdir(), ->find_folder(), trailingslashit(), trailingslashit(), ->is_dir(), ->delete(), move_dir(), is_wp_error() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 103 instructions, 5–84 executed per call, 10 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.
Uses · 4
- trailingslashit()Appends a trailing slash.
- move_dir()Moves a directory from one location to another.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- WP_Error::__construct()Initializes the error.
Used by · 1
- WP_Upgrader::install_package()Install a package.
Source code
public function move_to_temp_backup_dir( $args ) { global $wp_filesystem; if ( empty( $args['slug'] ) || empty( $args['src'] ) || empty( $args['dir'] ) ) { return false; } /* * Skip any plugin that has "." as its slug. * A slug of "." will result in a `$src` value ending in a period. * * On Windows, this will cause the 'plugins' folder to be moved, * and will cause a failure when attempting to call `mkdir()`. */ if ( '.' === $args['slug'] ) { return false; } if ( ! $wp_filesystem->wp_content_dir() ) { return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] ); } $dest_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/'; $sub_dir = $dest_dir . $args['dir'] . '/'; // Create the temporary backup directory if it does not exist. if ( ! $wp_filesystem->is_dir( $sub_dir ) ) { if ( ! $wp_filesystem->is_dir( $dest_dir ) ) { $wp_filesystem->mkdir( $dest_dir, FS_CHMOD_DIR ); } if ( ! $wp_filesystem->mkdir( $sub_dir, FS_CHMOD_DIR ) ) { // Could not create the backup directory. return new WP_Error( 'fs_temp_backup_mkdir', $this->strings['temp_backup_mkdir_failed'] ); } } $src_dir = $wp_filesystem->find_folder( $args['src'] ); $src = trailingslashit( $src_dir ) . $args['slug']; $dest = $dest_dir . trailingslashit( $args['dir'] ) . $args['slug']; // Delete the temporary backup directory if it already exists. if ( $wp_filesystem->is_dir( $dest ) ) { $wp_filesystem->delete( $dest, true ); } // Move to the temporary backup directory. $result = move_dir( $src, $dest, true ); if ( is_wp_error( $result ) ) { return new WP_Error( 'fs_temp_backup_move', $this->strings['temp_backup_move_failed'] ); } return true; }Changelog
Introduced in 6.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-wp-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.