public function set_demo_data($file) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } require_once ABSPATH . 'wp-admin/includes/import.php'; $importer_error = false; if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require_once $class_wp_importer; } else { $importer_error = true; } } if (!class_exists('WP_Import')) { $class_wp_import = dirname(__FILE__) . '/wordpress-importer.php'; if (file_exists($class_wp_import)) { require_once $class_wp_import; } else { $importer_error = true; } } if ($importer_error) { die("Error on import"); } else { if (!is_file($file)) { echo "The XML file containing the dummy content is not available or could not be read .. You might want to try to set the file permission to chmod 755.<br/>If this doesn't work please use the Wordpress importer and import the XML file (should be located in your download .zip: Sample Content folder) manually "; } else { $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; $wp_import->import($file); } } }
function kt_importer_content_callback() { $this->demoid = sanitize_title($_POST['demo']); $count = isset($_POST['count']) ? intval($_POST['count']) : 0; if ($count) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } require_once ABSPATH . 'wp-admin/includes/import.php'; if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; require_once $class_wp_importer; } if (!class_exists('WP_Import')) { $class_wp_import = dirname(__FILE__) . '/includes/wordpress-importer.php'; require_once $class_wp_import; } $this->content_file_name = $this->kt_importer_dir . $this->demoid . '/content_' . $count . '.xml'; if (!is_file($this->content_file_name)) { echo "The XML file containing the dummy content is not available or could not be read .. You might want to try to set the file permission to chmod 755.<br/>If this doesn't work please use the Wordpress importer and import the XML file (should be located in your download .zip: Sample Content folder) manually "; } else { $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; $returned_value = $wp_import->import($this->content_file_name); if (is_wp_error($returned_value)) { echo "An Error Occurred During Import"; } } } else { //Content imported successfully do_action('kt_importer_after_content_import', $this->demoid); } wp_die(); // this is required to terminate immediately and return a proper response }
/** * FILE: vibeimport.php * Author: Mr.Vibe * Credits: www.VibeThemes.com * Project: WPLMS */ function vibe_import($file) { require_once ABSPATH . 'wp-admin/includes/import.php'; $file_path = apply_filters('wplms_setup_import_file_path', VIBE_PATH . "/setup/data/{$file}.xml", $file); if (!class_exists('WP_Import')) { require_once 'wordpress-importer.php'; } if (class_exists('WP_Import')) { if (file_exists($file_path)) { do_action('wplms_before_sample_data_import', $file); $WP_Import = new WP_Import(); if (!function_exists('wp_insert_category')) { include ABSPATH . 'wp-admin/includes/taxonomy.php'; } if (!function_exists('post_exists')) { include ABSPATH . 'wp-admin/includes/post.php'; } if (!function_exists('comment_exists')) { include ABSPATH . 'wp-admin/includes/comment.php'; } $WP_Import->fetch_attachments = true; $WP_Import->allow_fetch_attachments(); $WP_Import->import($file_path); _e('Import Complete !', 'vibe'); echo '<a href="' . admin_url('options-permalink.php') . '" target="_blank" class="button button-primary" style="margin-top:15px;">' . __('Save Permalinks', 'vibe') . '</a><br />'; echo '<a href="' . admin_url('options-general.php?page=bp-components') . '" target="_blank" class="button button-primary" style="margin-top:15px;">' . __('Save Components', 'vibe') . '</a>'; do_action('wplms_after_sample_data_import', $file); } else { echo __("Unable to locate Sample Data file.", 'vibe'); } } else { echo __("Couldn't install the test demo data as we were unable to use the WP_Import class.", "vibe"); } }
/** * Import a WXR file. * * The $users parameter provides information on how users specified in the import * file should be imported. Each key is a user login name and indicates if the user * should be mapped to an existing user, created as a new user with a particular login * or imported with the information held in the WXR file. An example of this: * * <code> * $users = array( * 'alice' => 1, // alice will be mapped to user ID 1 * 'bob' => 'john', // bob will be transformed into john * 'eve' => false // eve will be imported as is * );</code> * * @param string $filename Full path of the file to import * @param array $users User import settings * @param bool $fetch_files Whether or not do download remote attachments */ protected function _import_wp($filename, $users = array(), $fetch_files = true) { $importer = new WP_Import(); $file = realpath($filename); assert('!empty($file)'); assert('is_file($file)'); $authors = $mapping = $new = array(); $i = 0; // each user is either mapped to a given ID, mapped to a new user // with given login or imported using details in WXR file foreach ($users as $user => $map) { $authors[$i] = $user; if (is_int($map)) { $mapping[$i] = $map; } else { if (is_string($map)) { $new[$i] = $map; } } $i++; } $_POST = array('imported_authors' => $authors, 'user_map' => $mapping, 'user_new' => $new); ob_start(); $importer->fetch_attachments = $fetch_files; $importer->import($file); ob_end_clean(); $_POST = array(); }
function us_dataImport() { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } require_once get_template_directory() . '/vendor/wordpress-importer/wordpress-importer.php'; if (!is_file(get_template_directory() . '/xml/demo_data.xml')) { echo "Automatic import failed. Please use the wordpress importer and import the XML file (Astra/xml/demo_data.xml) manually."; } else { $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; $wp_import->import(get_template_directory() . '/xml/demo_data.xml'); // Set menu $locations = get_theme_mod('nav_menu_locations'); $menus = wp_get_nav_menus(); if (!empty($menus)) { foreach ($menus as $menu) { if (is_object($menu) && $menu->name == 'Astra Main Menu') { $locations['astra_main_menu'] = $menu->term_id; } if (is_object($menu) && $menu->name == 'Astra Footer Menu') { $locations['astra_footer_menu'] = $menu->term_id; } } } set_theme_mod('nav_menu_locations', $locations); } die; }
function thb_import_data() { // Load Importer API require_once ABSPATH . 'wp-admin/includes/import.php'; $importerError = false; $file = get_template_directory() . "/inc/democontent/demo-content.xml"; if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require_once $class_wp_importer; } else { $importerError = true; } } if ($importerError !== false) { echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually."; } else { if (class_exists('WP_Importer')) { try { $importer = new WP_Import(); $importer->fetch_attachments = true; $importer->import($file); thb_update_options(); thb_update_menus('Main Menu', 'nav-menu'); thb_import_theme_options(); // thb_update_widgets(); die('Success!'); } catch (Exception $e) { echo "Error while importing"; } } } die; }
/** * Import a WXR file */ private function import_wxr($file, $args) { $wp_import = new WP_Import(); $import_data = $wp_import->parse($file); if (is_wp_error($import_data)) { return $import_data; } // Prepare the data to be used in process_author_mapping(); $wp_import->get_authors_from_import($import_data); $author_data = array(); foreach ($wp_import->authors as $wxr_author) { $author = new \stdClass(); // Always in the WXR $author->user_login = $wxr_author['author_login']; // Should be in the WXR; no guarantees if (isset($wxr_author['author_email'])) { $author->user_email = $wxr_author['author_email']; } if (isset($wxr_author['author_display_name'])) { $author->display_name = $wxr_author['author_display_name']; } if (isset($wxr_author['author_first_name'])) { $author->first_name = $wxr_author['author_first_name']; } if (isset($wxr_author['author_last_name'])) { $author->last_name = $wxr_author['author_last_name']; } $author_data[] = $author; } // Build the author mapping $author_mapping = $this->process_author_mapping($args['authors'], $author_data); if (is_wp_error($author_mapping)) { return $author_mapping; } $author_in = wp_list_pluck($author_mapping, 'old_user_login'); $author_out = wp_list_pluck($author_mapping, 'new_user_login'); // $user_select needs to be an array of user IDs $user_select = array(); $invalid_user_select = array(); foreach ($author_out as $author_login) { $user = get_user_by('login', $author_login); if ($user) { $user_select[] = $user->ID; } else { $invalid_user_select[] = $author_login; } } if (!empty($invalid_user_select)) { return new WP_Error('invalid-author-mapping', sprintf("These user_logins are invalid: %s", implode(',', $invalid_user_select))); } // Drive the import $wp_import->fetch_attachments = !in_array('attachment', $args['skip']); $_GET = array('import' => 'wordpress', 'step' => 2); $_POST = array('imported_authors' => $author_in, 'user_map' => $user_select, 'fetch_attachments' => $wp_import->fetch_attachments); if (in_array('image_resize', $args['skip'])) { add_filter('intermediate_image_sizes_advanced', array($this, 'filter_set_image_sizes')); } $wp_import->import($file); return true; }
function cmo_import_xml($demo_xml_file) { if (function_exists('check_ajax_referer')) { check_ajax_referer(DEMO_IMPORTER_NONCE, 'security'); } header('Content-type: text/html; charset=utf-8'); define('WP_LOAD_IMPORTERS', true); require_once ABSPATH . 'wp-admin/includes/import.php'; $import_error = false; if (!class_exists('WP_Importer')) { $wp_importer_file = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($wp_importer_file)) { require_once $wp_importer_file; } else { $import_error = true; } } if (!class_exists('WP_Import')) { require_once 'wordpress-importer/wordpress-importer.php'; } if ($import_error || !class_exists('WP_Import')) { ajax_finish(false, __('Failed to load importer php files. Use WordPress Importer plugin to manually load demo content xml file.', 'cumulo')); } if (!is_file($demo_xml_file)) { ajax_finish(true, "done"); } $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; set_time_limit(0); ob_start(); $wp_import->import($demo_xml_file); ob_get_clean(); ajax_finish(true, "done"); }
function etheme_import_data() { // Load Importer API require_once ABSPATH . 'wp-admin/includes/import.php'; $importerError = false; $file = get_template_directory() . "/code/dummy/Dummy.xml"; //check if wp_importer, the base importer class is available, otherwise include it if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require_once $class_wp_importer; } else { $importerError = true; } } if ($importerError !== false) { echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually."; } else { if (class_exists('WP_Importer')) { try { $importer = new WP_Import(); $importer->fetch_attachments = true; $importer->import($file); etheme_update_options(); etheme_update_widgets(); etheme_update_menus(); } catch (Exception $e) { echo "Error while importing"; } } } die; }
/** * FILE: vibeimport.php * Author: Mr.Vibe * Credits: www.VibeThemes.com * Project: WPLMS */ function vibe_import($file) { require_once ABSPATH . 'wp-admin/includes/import.php'; $file_path = apply_filters('wplms_setup_import_file_path', VIBE_PATH . "/setup/data/{$file}.xml", $file); if (!class_exists('WP_Import')) { require_once 'wordpress-importer.php'; } if (class_exists('WP_Import')) { if (file_exists($file_path)) { do_action('wplms_before_sample_data_import', $file); $WP_Import = new WP_Import(); if (!function_exists('wp_insert_category')) { include ABSPATH . 'wp-admin/includes/taxonomy.php'; } if (!function_exists('post_exists')) { include ABSPATH . 'wp-admin/includes/post.php'; } if (!function_exists('comment_exists')) { include ABSPATH . 'wp-admin/includes/comment.php'; } $WP_Import->fetch_attachments = true; $WP_Import->allow_fetch_attachments(); $WP_Import->import($file_path); do_action('wplms_after_sample_data_import', $file); _e('Import Complete !', 'vibe'); } else { echo __("Unable to locate Sample Data file.", 'vibe'); } } else { echo __("Couldn't install the test demo data as we were unable to use the WP_Import class.", "vibe"); } }
function import_content($folder = '', $file = 'content.xml.gz') { $import = new WP_Import(); $xml = get_template_directory() . '/library/import/files/' . $folder . '/' . $file; $import->fetch_attachments = $_POST && key_exists('attachments', $_POST) && $_POST['attachments'] ? true : false; ob_start(); $import->import($xml); ob_end_clean(); }
/** --------------------------------------------------------------------------- * Import | Content * ---------------------------------------------------------------------------- */ function import_content($file = 'all.xml.gz') { $import = new WP_Import(); $xml = LIBS_DIR . '/importer/demo/' . $file; // print_r($xml); $import->fetch_attachments = $_POST && key_exists('attachments', $_POST) && $_POST['attachments'] ? true : false; ob_start(); $import->import($xml); ob_end_clean(); }
function mtc_importer() { global $wpdb; if (current_user_can('manage_options') && isset($_GET['import_data_content'])) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } // we are loading importers if (!class_exists('WP_Importer')) { // if main importer class doesn't exist $wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; include $wp_importer; } if (!class_exists('WP_Import')) { // if WP importer doesn't exist $wp_import = get_template_directory() . '/admin/library/plugins/importer/wordpress-importer.php'; include $wp_import; } if (class_exists('WP_Importer') && class_exists('WP_Import')) { // check for main import class and wp import class $importer = new WP_Import(); $import_message = array(); /* First Import Posts, Pages, Portfolio Content, FAQ, Images, Menus */ $import_message[] = 'First Import Posts, Pages, Portfolio Content, FAQ, Images, Menus'; $theme_xml = get_template_directory() . '/admin/library/plugins/importer/data/bzine.xml.gz'; $importer->fetch_attachments = true; ob_start(); $importer->import($theme_xml); ob_end_clean(); /* Import Theme Options */ $import_message[] = 'Import Theme Options'; $theme_options_txt = get_template_directory_uri() . '/admin/library/plugins/importer/data/theme_options.txt'; // theme options data file $theme_options_txt = wp_remote_get($theme_options_txt); $data = unserialize(base64_decode($theme_options_txt['body'])); update_option(OPTIONS, $data); // update theme options /* Add data to widgets */ $import_message[] = 'Add data to widgets'; $widgets_json = get_template_directory_uri() . '/admin/library/plugins/importer/data/bzine_widget.json'; // widgets data file $widgets_json = wp_remote_get($widgets_json); $widget_data = $widgets_json['body']; $widget_data = json_decode($widget_data, true); update_option('sidebars_widgets', $widget_data['setting']); foreach ($widget_data['data'] as $key => $widget) { $dada = serialize($widget); update_option($key, $widget); } // finally redirect to success page wp_redirect(admin_url('themes.php?page=optionsframework&imported=success#of-option-generaloptions')); } } }
function import_xml() { $xml_file = get_template_directory() . '/framework/importer/data/sample-data.xml.gz'; if (file_exists($xml_file)) { $importer = new WP_Import(); $importer->fetch_attachments = true; ob_start(); $importer->import($xml_file); ob_end_clean(); } }
function etheme_import_data() { //delete_option('demo_data_installed');die(); if (!isset($_POST['version'])) { $style = 'e-commerce'; } else { $style = $_POST['version']; } // Load Importer API require_once ABSPATH . 'wp-admin/includes/import.php'; $importerError = false; $demo_data_installed = get_option('demo_data_installed'); switch ($style) { case 'e-commerce': $file = get_template_directory() . "/framework/dummy/Dummy.xml"; break; case 'corporate': $file = get_template_directory() . "/framework/dummy/Dummy_corpo.xml"; break; default: $file = get_template_directory() . "/framework/dummy/Dummy_corpo.xml"; } //check if wp_importer, the base importer class is available, otherwise include it if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require_once $class_wp_importer; } else { $importerError = true; } } if ($importerError !== false) { echo "The Auto importing script could not be loaded. Please use the wordpress importer and import the XML file that is located in your themes folder manually."; } else { if (class_exists('WP_Importer')) { try { if ($demo_data_installed != 'yes') { $importer = new WP_Import(); $importer->fetch_attachments = true; $importer->import($file); } etheme_update_options($style); etheme_update_menus(); die('Success!'); } catch (Exception $e) { echo "Error while importing"; } } } die; }
function vwdemo_start_import() { define('WP_LOAD_IMPORTERS', true); // Load all importer functions require VW_DEMO_IMPORT_PATH . '/wordpress-importer/wordpress-importer.php'; add_action('import_start', 'vwdemo_import_custom_sidebars', 91); add_action('import_start', 'vwdemo_import_widgets', 92); add_action('import_end', 'vwdemo_setup_menu'); add_action('import_end', 'vwdemo_setup_homepage'); add_action('import_end', 'vwdemo_setup_finish'); add_filter('http_request_args', 'vwdemo_disable_reject_unsafe_urls', 11, 2); $wp_import = new WP_Import(); $wp_import->fetch_attachments = $wp_import->allow_fetch_attachments(); // Import $file_path = VW_DEMO_IMPORT_PATH . '/demo-content/demo-content.xml'; if (file_exists($file_path)) { $wp_import->import($file_path); } die; }
function vwdemo_start_import() { define('WP_LOAD_IMPORTERS', true); error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); if (!class_exists('WP_Import')) { require_once get_template_directory() . '/framework/demo-importer/wordpress-importer/wordpress-importer.php'; } add_action('import_start', 'vwdemo_import_custom_sidebars', 91); add_action('import_start', 'vwdemo_import_widgets', 92); add_action('import_end', 'vwdemo_setup_menu'); add_action('import_end', 'vwdemo_setup_homepage'); add_filter('http_request_args', 'vwdemo_disable_reject_unsafe_urls', 11, 2); $wp_import = new WP_Import(); $wp_import->fetch_attachments = $wp_import->allow_fetch_attachments(); // Import $file_path = VW_DEMO_IMPORT_PATH . '/demo-content.xml'; if (file_exists($file_path)) { $wp_import->import($file_path); } die; }
function import_content($file = 'content.xml') { $xml = AZEXO_THEME_DIR . '/azexo/importer/data/' . $file; if (file_exists($xml)) { $import = new WP_Import(); $import->fetch_attachments = $_POST && key_exists('attachments', $_POST) && $_POST['attachments'] ? true : false; ob_start(); $import->import($xml); ob_end_clean(); // set home & blog page $home = get_page_by_title('Home'); $blog = get_page_by_title('Journal'); if ($home->ID && $blog->ID) { update_option('show_on_front', 'page'); update_option('page_on_front', $home->ID); // Front Page update_option('page_for_posts', $blog->ID); // Blog Page } } }
function handle_wp_import($data) { if (!class_exists('WP_Import')) { $wp_importer = get_template_directory() . '/lib/vendor/wordpress-importer/wordpress-importer.php'; if (is_readable($wp_importer)) { require $wp_importer; } else { return new WP_Error('wp_importer_missing', esc_html__('The WordPress importer class can\'t be found.', 'youxi')); } } $data = wp_parse_args($data, array('xml' => '', 'attachments_baseurl' => '', 'attachments_dir' => '')); // Import the content $wp_import = new WP_Import(); $wp_import->attachments_baseurl = $data['attachments_baseurl']; $wp_import->attachments_dir = $data['attachments_dir']; $wp_import->fetch_attachments = true; ob_start(); set_time_limit(0); $wp_import->import($data['xml']); return ob_get_clean(); }
public function import_content($file) { if (!class_exists('WP_Importer')) { ob_start(); $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; require_once $class_wp_importer; require_once get_template_directory() . '/includes/import/class.wordpress-importer.php'; $qode_import = new WP_Import(); set_time_limit(0); $path = get_template_directory() . '/includes/import/files/' . $file; $qode_import->fetch_attachments = $this->attachments; $returned_value = $qode_import->import($path); if (is_wp_error($returned_value)) { $this->message = __("An Error Occurred During Import", "qode"); } else { $this->message = __("Content imported successfully", "qode"); } ob_get_clean(); } else { $this->message = __("Error loading files", "qode"); } }
public function import_demo_content($data_file) { try { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } if (!class_exists('WP_Import')) { include dirname(__FILE__) . "/wordpress-importer.php"; } $xml_filepath = $data_file; if (!file_exists($xml_filepath)) { return false; } $importer = new WP_Import(); $importer->fetch_attachments = true; ob_start(); $importer->import($xml_filepath); ob_end_clean(); return true; } catch (Exception $e) { throw $e; } }
static function beginInstall() { global $easy_metadata, $config_suboption; EASYFInstallerHelper::createImages(); if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } if (!class_exists('WP_Import')) { $class_wp_import = EASY_F_PLUGIN_PATH . '/admin/importer/wordpress-importer.php'; if (file_exists($class_wp_import)) { require_once $class_wp_import; } } $import_file = EASY_F_PLUGIN_PATH . '/demo_data_here/dummy' . $config_suboption . '.xml'; if (is_file($import_file)) { $wp_import = new WP_Import(); $wp_import->fetch_attachments = false; if (isset($easy_metadata['data']->allow_attachment) && $easy_metadata['data']->allow_attachment == "yes") { $wp_import->fetch_attachments = true; } $wp_import->import($import_file); } }
function process_posts() { $menu_items = $mo_posts = array(); // store this for future usage as parent function unset $this->posts foreach ($this->posts as $post) { if ('nav_menu_item' == $post['post_type']) { $menu_items[] = $post; } if (0 === strpos($post['post_title'], 'polylang_mo_')) { $mo_posts[] = $post; } } if (!empty($mo_posts)) { new PLL_MO(); } // just to register the polylang_mo post type before processing posts parent::process_posts(); global $polylang; $polylang->model->clean_languages_cache(); // to update the posts count in (cached) languages list $this->remap_translations($this->post_translations, $this->processed_posts); unset($this->post_translations); // language switcher menu items foreach ($menu_items as $item) { foreach ($item['postmeta'] as $meta) { if ('_pll_menu_item' == $meta['key']) { update_post_meta($this->processed_menu_items[$item['post_id']], '_pll_menu_item', maybe_unserialize($meta['value'])); } } } // merge strings translations foreach ($mo_posts as $post) { $lang_id = (int) substr($post['post_title'], 12); if (!empty($this->processed_terms[$lang_id])) { if ($strings = unserialize($post['post_content'])) { $mo = new PLL_MO(); $mo->import_from_db($this->processed_terms[$lang_id]); foreach ($strings as $msg) { $mo->add_entry_or_merge($mo->make_entry($msg[0], $msg[1])); } $mo->export_to_db($this->processed_terms[$lang_id]); } } // delete the now useless imported post wp_delete_post($this->processed_posts[$post['post_id']], true); } }
function fusion_importer() { global $wpdb; if (current_user_can('manage_options') && isset($_GET['import_data_content'])) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } // we are loading importers if (!class_exists('WP_Importer')) { // if main importer class doesn't exist $wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; include $wp_importer; } if (!class_exists('WP_Import')) { // if WP importer doesn't exist $wp_import = get_template_directory() . '/framework/plugins/importer/wordpress-importer.php'; include $wp_import; } if (class_exists('WP_Importer') && class_exists('WP_Import')) { // check for main import class and wp import class $importer = new WP_Import(); /* First Import Posts, Pages, Portfolio Content, FAQ, Images, Menus */ $theme_xml = get_template_directory() . '/framework/plugins/importer/data/avada.xml.gz'; $importer->fetch_attachments = true; ob_start(); $importer->import($theme_xml); ob_end_clean(); /* Import Woocommerce if WooCommerce Exists */ if (class_exists('Woocommerce')) { $importer = new WP_Import(); $theme_xml = get_template_directory() . '/framework/plugins/importer/data/wooproducts.xml.gz'; $importer->fetch_attachments = true; ob_start(); $importer->import($theme_xml); ob_end_clean(); // Set pages $woopages = array('woocommerce_shop_page_id' => 'Shop', 'woocommerce_cart_page_id' => 'Cart', 'woocommerce_checkout_page_id' => 'Checkout', 'woocommerce_pay_page_id' => 'Checkout → Pay', 'woocommerce_thanks_page_id' => 'Order Received', 'woocommerce_myaccount_page_id' => 'My Account', 'woocommerce_edit_address_page_id' => 'Edit My Address', 'woocommerce_view_order_page_id' => 'View Order', 'woocommerce_change_password_page_id' => 'Change Password', 'woocommerce_logout_page_id' => 'Logout', 'woocommerce_lost_password_page_id' => 'Lost Password'); foreach ($woopages as $woo_page_name => $woo_page_title) { $woopage = get_page_by_title($woo_page_title); if ($woopage->ID) { update_option($woo_page_name, $woopage->ID); // Front Page } } // We no longer need to install pages delete_option('_wc_needs_pages'); delete_transient('_wc_activation_redirect'); // Flush rules after install flush_rewrite_rules(); } // Set imported menus to registered theme locations $locations = get_theme_mod('nav_menu_locations'); // registered menu locations in theme $menus = wp_get_nav_menus(); // registered menus if ($menus) { foreach ($menus as $menu) { // assign menus to theme locations if ($menu->name == 'Main') { $locations['main_navigation'] = $menu->term_id; } else { if ($menu->name == '404') { $locations['404_pages'] = $menu->term_id; } else { if ($menu->name == 'Top') { $locations['top_navigation'] = $menu->term_id; } } } } } set_theme_mod('nav_menu_locations', $locations); // set menus to locations // Import Theme Options $theme_options_txt = get_template_directory_uri() . '/framework/plugins/importer/data/theme_options.txt'; // theme options data file $theme_options_txt = wp_remote_get($theme_options_txt); $data = unserialize(base64_decode($theme_options_txt['body'])); update_option(OPTIONS, $data); // update theme options // Add sidebar widget areas $sidebars = array('ContactSidebar' => 'Contact Sidebar', 'FAQ' => 'FAQ', 'HomepageSidebar' => 'Home Page Sidebar', 'Portfolio' => 'Portfolio'); update_option('sbg_sidebars', $sidebars); foreach ($sidebars as $sidebar) { $sidebar_class = avada_name_to_class($sidebar); register_sidebar(array('name' => $sidebar, 'id' => 'avada-custom-sidebar-' . strtolower($sidebar_class), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="heading"><h3>', 'after_title' => '</h3></div>')); } // Add data to widgets $widgets_json = get_template_directory_uri() . '/framework/plugins/importer/data/widget_data.json'; // widgets data file $widgets_json = wp_remote_get($widgets_json); $widget_data = $widgets_json['body']; $import_widgets = fusion_import_widget_data($widget_data); // Import Layerslider if (function_exists('layerslider_import_sample_slider')) { // if layerslider is activated $ls_txt = get_template_directory_uri() . '/framework/plugins/importer/data/layerslider.txt'; // layerslider data file $ls_txt = wp_remote_get($ls_txt); $data = json_decode(base64_decode($ls_txt['body']), true); avada_import_sample_slider($data); // update theme options // Get all sliders // Table name $table_name = $wpdb->prefix . "layerslider"; // Get sliders $sliders = $wpdb->get_results("SELECT * FROM {$table_name}\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE flag_hidden = '0' AND flag_deleted = '0'\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY date_c ASC"); if (!empty($sliders)) { foreach ($sliders as $key => $item) { $slides[$item->id] = $item->name; } } if ($slides) { foreach ($slides as $key => $val) { $slides_array[$val] = $key; } } // Assign LayerSlider $lspage = get_page_by_title('Layer Slider'); if ($lspage->ID && $slides_array['Avada Full Width']) { update_post_meta($lspage->ID, 'pyre_slider', $slides_array['Avada Full Width']); } } // Import Revslider if (class_exists('UniteFunctionsRev')) { // if revslider is activated $rev_directory = get_template_directory() . '/framework/plugins/importer/data/revsliders/'; // layerslider data dir foreach (glob($rev_directory . '*.txt') as $filename) { // get all files from revsliders data dir $filename = basename($filename); $rev_files[] = get_template_directory_uri() . '/framework/plugins/importer/data/revsliders/' . $filename; } foreach ($rev_files as $rev_file) { // finally import rev slider data files $get_file = wp_remote_get($rev_file); $arrSlider = unserialize($get_file['body']); $sliderParams = $arrSlider["params"]; if (isset($sliderParams["background_image"])) { $sliderParams["background_image"] = UniteFunctionsWPRev::getImageUrlFromPath($sliderParams["background_image"]); } $json_params = json_encode($sliderParams); $arrInsert = array(); $arrInsert["params"] = $json_params; $arrInsert["title"] = UniteFunctionsRev::getVal($sliderParams, "title", "Slider1"); $arrInsert["alias"] = UniteFunctionsRev::getVal($sliderParams, "alias", "slider1"); $wpdb->insert(GlobalsRevSlider::$table_sliders, $arrInsert); $sliderID = mysql_insert_id(); //create all slides $arrSlides = $arrSlider["slides"]; foreach ($arrSlides as $slide) { $params = $slide["params"]; $layers = $slide["layers"]; //convert params images: if (isset($params["image"])) { $params["image"] = UniteFunctionsWPRev::getImageUrlFromPath($params["image"]); } //convert layers images: foreach ($layers as $key => $layer) { if (isset($layer["image_url"])) { $layer["image_url"] = UniteFunctionsWPRev::getImageUrlFromPath($layer["image_url"]); $layers[$key] = $layer; } } //create new slide $arrCreate = array(); $arrCreate["slider_id"] = $sliderID; $arrCreate["slide_order"] = $slide["slide_order"]; $arrCreate["layers"] = json_encode($layers); $arrCreate["params"] = json_encode($params); $wpdb->insert(GlobalsRevSlider::$table_slides, $arrCreate); } } } // Set reading options $homepage = get_page_by_title('Home Version 13'); $posts_page = get_page_by_title('Blog Large'); if ($homepage->ID && $posts_page->ID) { update_option('show_on_front', 'page'); update_option('page_on_front', $homepage->ID); // Front Page update_option('page_for_posts', $posts_page->ID); // Blog Page } // finally redirect to success page wp_redirect(admin_url('themes.php?page=optionsframework&imported=success#of-option-generaloptions')); } } }
public function import_vc_templates($file) { if (!class_exists('WP_Importer')) { ob_start(); require_once 'class.wordpress-importer.php'; $thememove_import = new WP_Import(); set_time_limit(0); $path = get_template_directory() . '/inc/import/files/' . $file; $thememove_import->fetch_attachments = $this->attachments; $returned_value = $thememove_import->import($path); echo $returned_value; die; if (is_wp_error($returned_value)) { $this->message = __("An Error Occurred During Import", "thememove"); } else { $this->message = __("Content imported successfully", "thememove"); } ob_get_clean(); } else { $this->message = __("Error loading files", "thememove"); } }
function us_demo_import_content() { set_time_limit(0); if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } require_once get_template_directory() . '/vendor/wordpress-importer/wordpress-importer.php'; //select which files to import // $aviable_demos = array ('demo1', 'demo2', ); // $demo_version = 'demo1'; // if (in_array($_POST['demo'], $aviable_demos)) { // $demo_version = $_POST['demo']; // } $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; ob_start(); $wp_import->import(get_template_directory() . '/xml/demo_data.xml'); ob_end_clean(); // Set menu $locations = get_theme_mod('nav_menu_locations'); $menus = wp_get_nav_menus(); if (!empty($menus)) { foreach ($menus as $menu) { if (is_object($menu) && $menu->name == 'Impreza Header Menu') { $locations['impeza_main_menu'] = $menu->term_id; } } } set_theme_mod('nav_menu_locations', $locations); //Set Front Page $front_page = get_page_by_title('Home'); if (isset($front_page->ID)) { update_option('show_on_front', 'page'); update_option('page_on_front', $front_page->ID); } echo 'ok'; die; }
function tbDummyData() { /* init */ global $wp_filesystem; if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } define('WP_LOAD_IMPORTERS', true); /* init importer */ require_once ABSPATH . 'wp-admin/includes/import.php'; $importer_error = false; if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require_once $class_wp_importer; } else { $importer_error = true; } } if (!class_exists('WP_Import')) { $class_wp_import = TB_INCLUDES . 'wordpress-importer/wordpress-importer.php'; if (file_exists($class_wp_import)) { require_once $class_wp_import; } else { $importer_error = true; } } if ($importer_error) { die("Import error! Please unninstall WP importer plugin and try again"); } $wp_import = new WP_Import(); /* attachments */ $wp_import->fetch_attachments = true; /* init post query */ $theme = isset($_POST['theme']) ? $_POST['theme'] : 'tbtheme'; $current_data = isset($_POST['current_data']) ? $_POST['current_data'] : ''; /* tb used theme */ update_option('tb-theme-primary', $theme); ob_start(); /* import slider, ess grid and widget setting */ switch ($current_data) { case 'options': $options_json = get_template_directory_uri() . '/inc/dummy/' . $theme . '/options.json'; $options = $wp_filesystem->get_contents($options_json); if ($options) { tbImportThemeOptions($options); } else { die('<br />Your server don\'t have permission read options file. Theme options isn\'t imported<br />'); } break; case 'slider': if (!tbImportRevSlider($theme)) { $msg = '<br />You haven\'t install Rev Slider plugin. Slider isn\'t imported<br />'; } die($msg); break; case 'grid': if (!tbImportEssGrid($theme)) { $msg = '<br />You haven\'t install Ess Grid plugin. Ess data isn\'t imported<br />'; } die($msg); break; case 'widget': $widgets_json = get_template_directory_uri() . '/inc/dummy/' . $theme . '/widget_data.json'; $widgets = $wp_filesystem->get_contents($widgets_json); if ($widgets) { $msg = ''; tbImportWidgetSetting($widgets); } else { $msg = '<br />Your server don\'t have permission read widgets setting file. Widgets setting isn\'t imported<br />'; } die($msg); break; default: if ($current_data == 15) { if (function_exists('cptui_create_custom_post_types')) { if (file_exists(get_template_directory() . '/inc/dummy/' . $theme . '/posttypes/post.json')) { $posttypes = $wp_filesystem->get_contents(get_template_directory_uri() . '/inc/dummy/' . $theme . '/posttypes/post.json'); update_option('cptui_post_types', json_decode($posttypes, true)); } if (file_exists(get_template_directory() . '/inc/dummy/' . $theme . '/posttypes/tax.json')) { $tax = $wp_filesystem->get_contents(get_template_directory_uri() . '/inc/dummy/' . $theme . '/posttypes/tax.json'); update_option('cptui_taxonomies', json_decode($tax, true)); } flush_rewrite_rules(); } } if ($current_data == 16) { /*delete old menu and import new.*/ foreach (get_terms('nav_menu') as $nav) { wp_delete_nav_menu($nav->slug); } } if (file_exists(get_template_directory() . '/inc/dummy/' . $theme . '/data/sample' . $current_data . '.xml')) { $wp_import->import(get_template_directory() . '/inc/dummy/' . $theme . '/data/sample' . $current_data . '.xml'); } break; } ob_end_clean(); /* Done */ if ($current_data == 16) { die('<br />Import is finished.'); } }
function pp_import_demo_content() { if (is_admin() && isset($_POST['demo']) && !empty($_POST['demo'])) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } // Load Importer API require_once ABSPATH . 'wp-admin/includes/import.php'; if (!class_exists('WP_Importer')) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if (file_exists($class_wp_importer)) { require $class_wp_importer; } } if (!class_exists('WP_Import')) { $class_wp_importer = get_template_directory() . "/modules/import/wordpress-importer.php"; if (file_exists($class_wp_importer)) { require $class_wp_importer; } } $import_files = array(); //Check import selected demo if (class_exists('WP_Import')) { switch ($_POST['demo']) { case 1: default: //Check if install Woocommerce if (!class_exists('Woocommerce')) { $import_filepath = get_template_directory() . "/cache/demos/1.xml"; } else { $import_filepath = get_template_directory() . "/cache/demos/1_woo.xml"; } $page_on_front = 3602; //Demo 1 Homepage ID $oldurl = 'http://themes.themegoods2.com/photome/demo'; break; } //Run and download demo contents $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; $wp_import->import($import_filepath); } //Setup default front page settings. update_option('show_on_front', 'page'); update_option('page_on_front', $page_on_front); //Set default custom menu settings $locations = get_theme_mod('nav_menu_locations'); $locations['primary-menu'] = 21; $locations['top-menu'] = 24; $locations['side-menu'] = 23; set_theme_mod('nav_menu_locations', $locations); //Change all URLs from demo URL to localhost $update_options = array(0 => 'content', 1 => 'excerpts', 2 => 'links', 3 => 'attachments', 4 => 'custom', 5 => 'guids'); $newurl = esc_url(site_url()); VB_update_urls($update_options, $oldurl, $newurl); exit; } }
function do_import() { $import_attachments = isset($_POST['webnus_importer_attachments']) && $_POST['webnus_importer_attachments'] == 'true' ? true : false; global $wpdb; if (!class_exists('WP_Import')) { include_once get_template_directory() . "/inc/plugins/wordpress-importer/wordpress-importer.php"; } $file_name = ''; if (isset($_POST['webnus_importer_filename'])) { $file_name = $_POST['webnus_importer_filename']; } $file_name = empty($file_name) ? 'dummy.xml' : $file_name; $myimporter = new WP_Import(); ob_start(); $myimporter->fetch_attachments = false; //$import_attachments; $myimporter->import(get_template_directory() . '/inc/dummy-data/' . $file_name); ob_end_clean(); echo 'Done! Demo data imported.'; die; }
function us_demo_import_content() { global $us_template_directory; $config = us_config('demo-import'); set_time_limit(0); if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', TRUE); } require_once $us_template_directory . '/framework/vendor/wordpress-importer/wordpress-importer.php'; //select which files to import $aviable_demos = array_keys($config); $demo_version = $aviable_demos[0]; if (in_array($_POST['demo'], $aviable_demos)) { $demo_version = $_POST['demo']; } $wp_import = new WP_Import(); $wp_import->fetch_attachments = TRUE; ob_start(); $wp_import->import($us_template_directory . '/demo-import/' . $demo_version . '-data.xml'); ob_end_clean(); // Set menu if (isset($config[$demo_version]['nav_menu_locations'])) { $locations = get_theme_mod('nav_menu_locations'); $menus = wp_get_nav_menus(); if (!empty($menus)) { foreach ($menus as $menu) { if (is_object($menu) and isset($config[$demo_version]['nav_menu_locations'][$menu->name])) { $nav_location_key = $config[$demo_version]['nav_menu_locations'][$menu->name]; $locations[$nav_location_key] = $menu->term_id; } } } set_theme_mod('nav_menu_locations', $locations); } // Set Front Page if (isset($config[$demo_version]['front_page'])) { $front_page = get_page_by_title($config[$demo_version]['front_page']); if (isset($front_page->ID)) { update_option('show_on_front', 'page'); update_option('page_on_front', $front_page->ID); } } wp_send_json_success(); }