/** * Helper function used only in this view. * It renders a list with sidebar-replacement details */ function list_sidebar_replacement($label, $list) { $import = CustomSidebarsExport::get_import_data(); $theme_sidebars = CustomSidebars::get_sidebars(); foreach ($list as $from_id => $to_id) { $from = $theme_sidebars[$from_id]; $to = array(); if (isset($theme_sidebars[$to_id])) { $to = $theme_sidebars[$to_id]; } else { $to = $import['sidebars'][$to_id]; } ?> <tr> <th scope="row"><?php echo esc_html($label); ?> </th> <td><?php echo esc_html($from['name']); ?> </td> <td><i class="dashicons dashicons-arrow-right-alt hint"></i></td> <td><?php echo esc_html($to['name']); ?> </td> </tr> <?php } }
/** * Loads the import-data into the self::$import_data property. * The data was prepared by the import-preview screen. * Populates the response object. * * @since 2.0 * @param object $req Initial response object for JSON response. * @return object Updated response object. */ private function prepare_import_data($req) { $data = json_decode(base64_decode(@$_POST['import_data']), true); if (is_array($data['meta']) && is_array($data['sidebars']) && is_array($data['options']) && is_array($data['widgets']) && is_array($data['categories'])) { $data['ignore'] = array(); self::$import_data = $data; // Remove details that does not exist on current blog. $this->prepare_data(); // "selected_data" only contains the items that were selected for import. $this->selected_data = self::$import_data; unset($this->selected_data['meta']); unset($this->selected_data['categories']); unset($this->selected_data['ignore']); if (!isset($_POST['import_plugin_config'])) { unset($this->selected_data['options']); } if (!isset($_POST['import_widgets'])) { unset($this->selected_data['widgets']); } else { foreach ($this->selected_data['widgets'] as $id => $widgets) { $key = 'import_sb_' . $id; if (!isset($_POST[$key])) { unset($this->selected_data['widgets'][$id]); } } } foreach ($this->selected_data['sidebars'] as $id => $sidebar) { $key = 'import_sb_' . $sidebar['id']; if (!isset($_POST[$key])) { unset($this->selected_data['sidebars'][$id]); } } // Finally: Import the config! $req = $this->do_import($req); } else { return self::req_err($req, __('Something unexpected happened and we could not finish ' . 'the import. Please try again.', CSB_LANG)); } return $req; }