public function clear_destination($destination) { global $wp_filesystem; if (!is_dir($destination) || !file_exists("{$destination}/style.css")) { // This is an installation not an upgrade. return parent::clear_destination($destination); } $backup_url = $this->create_backup($destination); if (!is_wp_error($backup_url)) { /* translators: 1: theme zip URL */ $this->skin->feedback(sprintf(__('A backup zip file of the old theme version can be downloaded <a href="%1$s">here</a>.', 'easy-theme-and-plugin-upgrades'), $backup_url)); // Restore default strings and display the original remove_old message. $this->upgrade_strings(); $this->skin->feedback('remove_old'); return parent::clear_destination($destination); } $this->skin->error($backup_url); $this->skin->feedback(__('Moving the old version of the theme to a new directory…', 'easy-theme-and-plugin-upgrades')); $headers = array('version' => 'Version'); $data = get_file_data("{$destination}/style.css", $headers); $new_name = basename($destination) . "-{$data['version']}"; $directory = dirname($destination); for ($x = 0; $x < 20; $x++) { $test_name = $new_name . '-' . $this->get_random_characters(10, 20); if (!is_dir("{$directory}/{$test_name}")) { $new_name = $test_name; break; } } if (is_dir("{$directory}/{$new_name}")) { // We gave it our best effort. Time to give up on the idea of having a backup. $this->skin->error(__('Unable to find a new directory name to move the old version of the theme to. No backup will be created.', 'easy-theme-and-plugin-upgrades')); } else { $result = $wp_filesystem->move($destination, "{$directory}/{$new_name}"); if ($result) { /* translators: 1: new theme directory name */ $this->skin->feedback(sprintf(__('Moved the old version of the theme to a new theme directory named %1$s. This directory should be backed up and removed from the site.', 'easy-theme-and-plugin-upgrades'), "<code>{$new_name}</code>")); } else { $this->skin->error(__('Unable to move the old version of the theme to a new directory. No backup will be created.', 'easy-theme-and-plugin-upgrades')); } } // Restore default strings and display the original remove_old message. $this->upgrade_strings(); $this->skin->feedback('remove_old'); return parent::clear_destination($destination); }