Restores the plugin or theme from temporary backup.
$temp_backupsarray[]optional
...$0 arraydir stringslug stringsrc stringWP_PLUGIN_DIR.Default:array()
public function restore_temp_backup( array $temp_backups = array() ) {
global $wp_filesystem;
$errors = new WP_Error();
if ( empty( $temp_backups ) ) {
$temp_backups = $this->temp_restores;
}
foreach ( $temp_backups as $args ) {
if ( empty( $args['slug'] ) || empty( $args['src'] ) || empty( $args['dir'] ) ) {
return false;
}
if ( ! $wp_filesystem->wp_content_dir() ) {
$errors->add( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
return $errors;
}
$src = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/' . $args['dir'] . '/' . $args['slug'];
$dest_dir = $wp_filesystem->find_folder( $args['src'] );
$dest = trailingslashit( $dest_dir ) . $args['slug'];
if ( $wp_filesystem->is_dir( $src ) ) {
// Cleanup.
if ( $wp_filesystem->is_dir( $dest ) && ! $wp_filesystem->delete( $dest, true ) ) {
$errors->add(
'fs_temp_backup_delete',
sprintf( $this->strings['temp_backup_restore_failed'], $args['slug'] )
);
continue;
}
// Move it.
$result = move_dir( $src, $dest, true );
if ( is_wp_error( $result ) ) {
$errors->add(
'fs_temp_backup_delete',
sprintf( $this->strings['temp_backup_restore_failed'], $args['slug'] )
);
continue;
}
}
}
return $errors->has_errors() ? $errors : true;
}
You must log in before being able to contribute a note or feedback.
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_upgrader/restore_temp_backup