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 ?>
'.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'] .= '
';
$class = (!defined('UPDRAFTPLUS_SELECT2_ENABLE') || UPDRAFTPLUS_SELECT2_ENABLE) ? 'updraft_select2' : '';
$info['addui'] .= '