get_wordpress_version(), '3.5', '>=')) { // Both MU and normal site add_filter('updraftplus_restore_all_downloaded_postscan', array($this, 'restore_all_downloaded_postscan'), 10, 7); // MU add_filter('updraftplus_restore_this_table', array($this, 'restore_this_table'), 10, 3); // MU add_filter('updraftplus_pre_restore_move_in', array($this, 'pre_restore_move_in'), 10, 7); add_action('updraftplus_restorer_restore_options', array($this, 'restorer_restore_options')); // MU add_filter('updraftplus_restore_delete_recursive', array($this, 'restore_delete_recursive'), 10, 4); add_action('updraftplus_admin_enqueue_scripts', array($this, 'updraftplus_admin_enqueue_scripts')); } } public function updraftplus_admin_enqueue_scripts() { global $updraftplus; $updraftplus->enqueue_select2(); } public function restore_delete_recursive($recurse, $ud_foreign, $restore_options, $type) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. if ($recurse) return $recurse; // If doing a single-site-to-multisite import on the uploads, then we expect subdirectories to be around - they need deleting without raising any user-visible errors return ('uploads' == $type && !empty($this->new_blogid)) ? true : $recurse; } public function pre_restore_move_in($now_done, $type, $working_dir, $info, $backup_info, $restorer, $wp_filesystem_dir) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. if ($now_done) return $now_done; if (is_multisite() && 0 == $restorer->ud_backup_is_multisite && (('plugins' == $type || 'themes' == $type) || ('uploads' == $type && !empty($this->new_blogid) && !get_site_option('ms_files_rewriting')))) { global $wp_filesystem, $updraftplus; $skin = $restorer->ud_get_skin(); // Migrating a single site into a multisite if ('plugins' == $type || 'themes' == $type) { $move_from = $restorer->get_first_directory($working_dir, array(basename($info['path']), $type)); // Only move in entities that are not already there $move_mode = Updraft_Restorer::MOVEIN_DO_NOTHING_IF_EXISTING; $skin->feedback('moving_backup'); $new_move_failed = (false === $move_from) ? true : false; if (false === $new_move_failed) { $move_in = $restorer->move_backup_in($move_from, trailingslashit($wp_filesystem_dir), $move_mode, array(), $type, true); if (is_wp_error($move_in)) return $move_in; if (!$move_in) $new_move_failed = true; } if ($new_move_failed) return new WP_Error('new_move_failed', $restorer->strings['new_move_failed']); @$wp_filesystem->delete($move_from);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Silenced to suppress errors that may arise because of the method. // Nothing more needs doing $now_done = true; } elseif ('uploads' == $type) { $skin->feedback('moving_old'); switch_to_blog($this->new_blogid); $ud = wp_upload_dir(); $wpud = $ud['basedir']; $fsud = trailingslashit($wp_filesystem->find_folder($wpud)); restore_current_blog(); if (!is_string($fsud)) { $updraftplus->log("Could not find basedir folder for site ($wpud)"); return new WP_Error('new_move_failed', $restorer->strings['new_move_failed']); } $updraftplus->log("Will move into: ".$fsud); return $fsud; // This now drops through to the uploads section } } return $now_done; } public function restorer_restore_options($restore_options) { $this->restore_options = $restore_options; } public function restore_this_table($restore_or_not, $unprefixed_table_name, $restore_options) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Unused parameter is present because the method is used as a WP filter. // We're only interested in filtering out the user/usermeta table when importing single site into multisite if (!$restore_or_not || empty($this->new_blogid)) return $restore_or_not; // Don't restore these - they're not used if ('users' == $unprefixed_table_name || 'usermeta' == $unprefixed_table_name) return false; return $restore_or_not; } /** * Runs upon the WP filter updraftplus_get_history_status_result * * @param Array $result - the pre-filtered information * * @return Array - after our filtering */ public function get_history_status_result($result) { if (!is_array($result)) return $result; ob_start(); $this->updraftplus_migrate_tab_output(); $tab_output = ob_get_contents(); ob_end_clean(); $result['migrate_tab'] = $tab_output; return $result; } /** * Display HTML for Migrate tab in 'Migrate/Clone' settings tab. * * @return void Display HTML. */ public function updraftplus_migrate_tab_output() { global $updraftplus, $updraftplus_admin;// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Its used on line 187 but for some reason its flagged assuming becuase of the closed and open php tags ?>
include_template('wp-admin/settings/temporary-clone.php'); ?>

migrate_widget(); do_action('updraft_migrate_after_widget'); ?>
'; echo '
'; echo ''; echo '

'.esc_html__('Restore an existing backup set onto this site', 'updraftplus').'

'; echo '
'; echo ''.esc_html__('To import a backup set, go to the "Existing backups" section in the "Backup/Restore" tab', 'updraftplus').""; if (empty($backup_history)) { echo '

'.esc_html__('This site has no backups to restore from yet.', 'updraftplus').'

'; echo ''; return; } $incremental_set_found = false; echo '

'; echo ''; echo '

'; if ($incremental_set_found) echo '

'.esc_html__('For incremental backups, you will be able to choose which increments to restore at a later stage.', 'updraftplus').'

'; echo ''; } public function restored_themes_one($theme) { // Network-activate $allowed_themes = get_site_option('allowedthemes'); $allowed_themes[$theme] = true; update_site_option('allowedthemes', $allowed_themes); global $updraftplus; $updraftplus->log(__('Network activating theme:', 'updraftplus').' '.$theme, 'notice-restore'); $updraftplus->log('Network activating theme: '.$theme); } public function restore_set_table_prefix($import_table_prefix, $backup_is_multisite) { if (!is_multisite() || 0 !== $backup_is_multisite) return $import_table_prefix; $new_blogid = $this->generate_new_blogid(); if (!is_integer($new_blogid)) return $new_blogid; do_action('updraftplus_restore_set_table_prefix_multisite_got_new_blog_id', $new_blogid, $import_table_prefix); $this->new_blogid = $new_blogid; return (string) $import_table_prefix.$new_blogid.'_'; } /** * WordPress action updraftplus_restore_all_downloaded_postscan called during the restore process. * * The last four parameters can be edited in-place. * * @param Array $backups - list of backups * @param Integer $timestamp - the timestamp (epoch time) of the backup being restored * @param Array $elements - elements being restored (as the keys of the array) * @param Array $info - information about the backup being restored * @param Array $mess - array of informational-level messages * @param Array $warn - array of warning-level messages * @param Array $err - array of error-level messages */ public function restore_all_downloaded_postscan($backups, $timestamp, $elements, &$info, &$mess, &$warn, &$err) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Unused parameter is present because the method is used as a WP filter. if (is_array($info) && is_multisite() && isset($info['multisite']) && !$info['multisite']) { $original_error_count = count($err); if (!empty($elements['wpcore'])) { $err[] = sprintf(__('You selected %s to be included in the restoration - this cannot / should not be done when importing a single site into a network.', 'updraftplus'), __('WordPress core', 'updraftplus')).' '.__('Go here for more information.', 'updraftplus').''; } if (!empty($elements['others'])) { $err[] = sprintf(__('You selected %s to be included in the restoration - this cannot / should not be done when importing a single site into a network.', 'updraftplus'), __('other content from wp-content', 'updraftplus')).' '.__('Go here for more information.', 'updraftplus').''; } if (!empty($elements['mu-plugins'])) { $err[] = sprintf(__('You selected %s to be included in the restoration - this cannot / should not be done when importing a single site into a network.', 'updraftplus'), __('Must-use plugins', 'updraftplus')).' '.__('Go here for more information.', 'updraftplus').''; } global $updraftplus; if (version_compare($updraftplus->get_wordpress_version(), '3.5', '<')) { $err[] = __('Importing a single site into a multisite install', 'updraftplus').': '.sprintf(__('This feature requires %s version %s or later', 'updraftplus'), 'WordPress', '3.5'); } elseif (get_site_option('ms_files_rewriting')) { $err[] = __('Importing a single site into a multisite install', 'updraftplus').': '.sprintf(__('This feature is not compatible with %s', 'updraftplus'), 'pre-WordPress-3.5-style multisite uploads rewriting', 'updraftplus'); } if (count($err) > $original_error_count) return; if (empty($info['addui'])) $info['addui'] = ''; $info['addui'] .= '

'.__('Information needed to continue:', 'updraftplus').'
'; $info['addui'] .= __('Enter details for where this new site is to live within your multisite install:', 'updraftplus').'
'; global $current_site; if (!is_subdomain_install()) { $info['addui'] .= '
'; } else { $info['addui'] .= ' .
'; } $info['addui'] .= '

'; if (!empty($elements['db'])) { if (empty($info['addui'])) $info['addui'] = ''; $info['addui'] .= '


'; $class = (!defined('UPDRAFTPLUS_SELECT2_ENABLE') || UPDRAFTPLUS_SELECT2_ENABLE) ? 'updraft_select2' : ''; $info['addui'] .= ''; // $main_site_id = $current_site->blog_id; $page = 0; while (!isset($users) || count($users) > 0) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- The variable is defined inside the loop. $users = get_users(array( // Not documented in codex, but the source reveals that to get "all sites", you use an ID of 0 'blog_id' => 0, 'offset' => $page * 500, 'number' => 500, 'fields' => array('ID', 'user_login', 'user_nicename'), )); if (!is_array($users)) $users = array(); foreach ($users as $user) { $info['addui'] .= ''; } $page++; } $info['addui'] .= '

'; } } } private function generate_new_blogid() { $blog_title = __('Migrated site (from UpdraftPlus)', 'updraftplus'); if (!isset($this->restore_options['updraftplus_migrate_blogname'])) { return new WP_Error('multisite_info_missing', sprintf(__('Required information for restoring this backup was not given (%s)', 'updraftplus'), 'new multisite import location')); } // Verify value given $result = wpmu_validate_blog_signup($this->restore_options['updraftplus_migrate_blogname'], $blog_title); if (!empty($result['errors']) && is_wp_error($result['errors']) && $result['errors']->get_error_code()) { return $result['errors']; } global $wpdb, $updraftplus; if (domain_exists($result['domain'], $result['path'], $wpdb->siteid)) { return new WP_Error('already_taken', sprintf(__('Error: %s', 'updraftplus'), 'Site URL already taken')); } $create = $this->create_empty_blog($result['domain'], $result['path'], $blog_title, $wpdb->siteid); if (is_integer($create)) { $url = untrailingslashit($result['domain'].$result['path']); $updraftplus->log(__('New site:', 'updraftplus').' '.$url, 'notice-restore'); switch_to_blog($create); // Update record of what we want to rewrite the URLs to in the search/replace operation $this->siteurl = untrailingslashit(site_url()); $this->home = untrailingslashit(home_url()); // The next line can't work, because content_url() fetches from the constant WP_CONTENT_URL // $this->content = untrailingslashit(content_url()); $wp_upload_dir = wp_upload_dir(); $this->uploads = $wp_upload_dir['baseurl']; if (is_subdomain_install()) { // For some reason, wp_upload_dir() on a subdomain install tends to return a URL with the host set to a different site's domain, despite switch_to_blog() having been called. Try to detect + fix this (though, it also usually won't matter anyway). $uploads_host = parse_url($this->uploads, PHP_URL_HOST); $expected_uploads_host = parse_url($this->home, PHP_URL_HOST); if ($uploads_host && $expected_uploads_host && $uploads_host != $expected_uploads_host) { $this->uploads = UpdraftPlus_Manipulation_Functions::str_replace_once($uploads_host, $expected_uploads_host, $this->uploads); $updraftplus->log("wp_upload_dir() returned an unexpected uploads hosts on a subdomain multisite ($uploads_host, rather than $expected_uploads_host) - correcting; destination uploads URL is now: ".$this->uploads); } } // We have to assume that on the imported site, uploads is at /uploads relative to the content directory if (empty($this->old_uploads)) $this->old_uploads = $this->old_content.'/uploads'; $this->content = false; $this->old_content = false; // $this->siteurl = 'http://'.$url; // $this->home = 'http://'.$url; // $this->content = // ?? restore_current_blog(); return $create; } elseif (is_wp_error($create)) { // Currently returns strings for errors, but being ready in case it improves doesn't hurt. return $create; } else { // Things like __('ERROR: problem creating site entry.' ) $updraftplus->log(__('Error when creating new site at your chosen address:', 'updraftplus'), 'warning-restore'); return new WP_Error('create_empty_blog_failed', __('Error when creating new site at your chosen address:', 'updraftplus').' '.(is_string($create) ? $create : print_r($create, true))); } } /** * Deprecated in WP 4.4 - https://core.trac.wordpress.org/changeset/34753 - hence, folded into the plugin instead * * @param string $domain * @param string $path * @param string $weblog_title * @param integer $site_id */ public function create_empty_blog($domain, $path, $weblog_title, $site_id = 1) { // Out of an abundance of caution, call the native, un-deprecated version if there is one global $updraftplus; $wp_version = $updraftplus->get_wordpress_version(); if (version_compare($wp_version, '4.4', '<') && function_exists('create_empty_blog')) return create_empty_blog($domain, $path, $weblog_title, $site_id); if (empty($path)) $path = '/'; // Check if the domain has been used already. We should return an error message. if (domain_exists($domain, $path, $site_id)) return __('ERROR: Site URL already taken.'); // Need to backup wpdb table names, and create a new wp_blogs entry for new blog. // Need to get blog_id from wp_blogs, and create new table names. // Must restore table names at the end of function. // insert_blog() and install_blog() are deprecated as of WP 5.1.0. // This has also caused an error when using install_blog on 5.1+, so we have switched to the new 'wp_insert_site' if (version_compare($wp_version, '5.1', '<')) { if (!$blog_id = insert_blog($domain, $path, $site_id)) return __('ERROR: problem creating site entry.'); switch_to_blog($blog_id); install_blog($blog_id); restore_current_blog(); } else { $admins = get_users(array( 'login__in' => get_super_admins(), 'fields' => array( 'user_ID') )); $user_id = 0; if (is_array($admins) && !empty($admins)) { $user_id = $admins[0]->ID; } $blog_data = array( 'domain' => $domain, 'path' => $path, 'network_id' => $site_id, 'title' => $weblog_title, 'user_id' => $user_id, ); $blog_id = wp_insert_site($blog_data); } return $blog_id; } public function updraftplus_restore_db_record_old_content($old_content) { // Only record once if (!empty($this->old_content)) return; $this->old_content = $old_content; } public function updraftplus_restore_db_record_old_uploads($old_uploads) { // Only record once if (!empty($this->old_uploads)) return; $this->old_uploads = $old_uploads; } } global $updraftplus_addons_migrator; if (!is_a($updraftplus_addons_migrator, 'UpdraftPlus_Addons_Migrator')) $updraftplus_addons_migrator = new UpdraftPlus_Addons_Migrator; if (!class_exists('UpdraftPlus_Addons_Migrator_RemoteSend_UI')) updraft_try_include_file('includes/class-remote-send.php', 'require_once'); if (!class_exists('UpdraftPlus_Addons_Migrator_RemoteSend')) { class UpdraftPlus_Addons_Migrator_RemoteSend extends UpdraftPlus_RemoteSend { public function __construct() { parent::__construct(); add_action('updraft_migrate_after_widget', array($this, 'updraft_migrate_after_widget')); add_action('admin_footer', array($this, 'admin_footer')); } /** * Display HTML for sending/receiving backups from/to remote sites in Migrate Tab. * Callback registered for `updraft_migrate_after_widget` action. * * @return void Display HTML. */ public function updraft_migrate_after_widget() { ?>

get_remotesites_selector(false, true);?>


list_our_keys(false, true);?>