Moves the plugin or theme being updated into a temporary backup directory.
Parameters
$args
string[]required- Array of data for the temporary backup.
slug
stringPlugin or theme slug.src
stringPath to the root directory for plugins or themes.dir
stringDestination subdirectory name. Accepts'plugins'
or'themes'
.
Source
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
Version | Description |
---|---|
6.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.