コード例 #1
0
ファイル: importer.php プロジェクト: rinodung/live-theme
function porto_import()
{
    global $wpdb, $porto_settings;
    if (current_user_can('manage_options') && isset($_GET['import_sample_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 = porto_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
            // update visual composer content types
            update_option('wpb_js_content_types', array('post', 'page', 'block', 'faq', 'member', 'portfolio'));
            $importer = new WP_Import();
            // Import Woocommerce Products
            if (class_exists('WooCommerce')) {
                // update woocommerce image sizes
                $catalog = array('width' => '300', 'height' => '400', 'crop' => 1);
                $single = array('width' => '500', 'height' => '666', 'crop' => 1);
                $thumbnail = array('width' => '90', 'height' => '90', 'crop' => 1);
                // Image sizes
                add_image_size('shop_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop']);
                add_image_size('shop_catalog', $catalog['width'], $catalog['height'], $catalog['crop']);
                add_image_size('shop_single', $single['width'], $single['height'], $single['crop']);
                $theme_xml = porto_plugins . '/importer/data/dummy_data_with_woo.xml.gz';
                $importer->fetch_attachments = true;
                ob_start();
                $importer->import($theme_xml);
                ob_end_clean();
                // Set woocommerce pages
                $woopages = array('woocommerce_shop_page_id' => 'Shop', 'woocommerce_cart_page_id' => 'Cart', 'woocommerce_checkout_page_id' => 'Checkout', 'woocommerce_myaccount_page_id' => 'My Account');
                foreach ($woopages as $woo_page_name => $woo_page_title) {
                    $woopage = get_page_by_title($woo_page_title);
                    if (isset($woopage) && $woopage->ID) {
                        update_option($woo_page_name, $woopage->ID);
                        // Front Page
                    }
                }
                // We no longer need to install pages
                $notices = array_diff(get_option('woocommerce_admin_notices', array()), array('install', 'update'));
                update_option('woocommerce_admin_notices', $notices);
                delete_option('_wc_needs_pages');
                delete_transient('_wc_activation_redirect');
                // Flush rules after install
                flush_rewrite_rules();
            } else {
                $theme_xml = porto_plugins . '/importer/data/dummy_data_without_woo.xml.gz';
                $importer->fetch_attachments = true;
                ob_start();
                $importer->import($theme_xml);
                ob_end_clean();
            }
            // 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 Menu') {
                        $locations['main_menu'] = $menu->term_id;
                    } else {
                        if ($menu->name == 'Top Navigation') {
                            $locations['top_nav'] = $menu->term_id;
                        } else {
                            if ($menu->name == 'View Switcher') {
                                $locations['view_switcher'] = $menu->term_id;
                            } else {
                                if ($menu->name == 'Currency Switcher') {
                                    $locations['currency_switcher'] = $menu->term_id;
                                }
                            }
                        }
                    }
                }
            }
            set_theme_mod('nav_menu_locations', $locations);
            // set menus to locations
            // Add widgets
            $widgets_json = porto_plugins_uri . '/importer/data/widget_data.json';
            $widgets_json = wp_remote_get($widgets_json);
            $widget_data = $widgets_json['body'];
            $import_widgets = porto_import_widget_data($widget_data);
            // Set reading options
            if (!isset($porto_settings)) {
                $page_title = 'Home Version 1';
            } else {
                if (!isset($porto_settings['theme-type'])) {
                    $page_title = 'Home Version 1';
                } else {
                    if ($porto_settings['theme-type'] == '_rtl') {
                        $page_title = 'Home RTL Version';
                    } else {
                        if (!$porto_settings['theme-type']) {
                            $page_title = 'Home Version 1';
                        } else {
                            $page_title = 'Home Version ' . str_replace('_', '', $porto_settings['theme_type']);
                        }
                    }
                }
            }
            $homepage = get_page_by_title($page_title);
            $posts_page = get_page_by_title('Blog');
            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
            }
            // Import master slider
            if (class_exists('MSP_Importer') && $porto_settings['import-master']) {
                for ($i = 1; $i < 6; $i++) {
                    $master_slider_json = porto_plugins_uri . '/importer/data/master_slider_' . $i . '.json';
                    $master_slider_json = wp_remote_get($master_slider_json);
                    $master_slider_json = $master_slider_json['body'];
                    $master_slider_importer = new MSP_Importer();
                    ob_start();
                    $master_slider_importer->import_data($master_slider_json);
                    ob_end_clean();
                }
            }
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&import_success=true'));
            exit;
        }
    }
}
コード例 #2
0
function lbmn_wordpress_content_importer()
{
    $theme_dir = get_template_directory();
    if (is_admin() && isset($_GET['importcontent'])) {
        if (!defined('WP_LOAD_IMPORTERS')) {
            define('WP_LOAD_IMPORTERS', true);
        }
        if (!class_exists('WP_Importer')) {
            $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
            if (file_exists($class_wp_importer)) {
                include $class_wp_importer;
            }
        }
        if (!class_exists('lbmn_WP_Import')) {
            $class_wp_import = $theme_dir . '/inc/importer/wordpress-importer.php';
            if (file_exists($class_wp_import)) {
                include $class_wp_import;
            }
        }
        if (class_exists('WP_Importer') && class_exists('lbmn_WP_Import')) {
            $importer = new lbmn_WP_Import();
            $files_to_import = array();
            // Live Composer has links to images hard-coded, so before importing
            // media we need to check that the Settings > Media >
            // 'Organize my uploads into month- and year-based folders' unchecked
            // as on demo server. After import is done we set back original state
            // of this setting.
            $setting_original_useyearmonthfolders = get_option('uploads_use_yearmonth_folders');
            update_option('uploads_use_yearmonth_folders', 0);
            if ($_GET['importcontent'] == 'basic-templates') {
                $import_path = $theme_dir . '/design/basic-config/';
                $files_array = array('start' => array(), 'templates' => array('files' => array('seowp-templates.xml.gz'), 'description' => __('Importing: Post Templates...', 'lbmn')), 'templates-system' => array('files' => array('seowp-systempagetemplates.xml.gz'), 'description' => __('Importing: System Templates...', 'lbmn')), 'menu-topbar' => array('files' => array('seowp-topbar.xml.gz'), 'description' => __('Importing: Top Bar Menu...', 'lbmn')), 'menu-topbar-config' => array('description' => __('Configuring Top Bar...', 'lbmn')), 'menu-basic' => array('files' => array('seowp-basicmenu.xml.gz'), 'description' => __('Importing: Basic Main Menu...', 'lbmn')), 'menu-basic-config' => array('description' => __('Configuring Basic Menu...', 'lbmn')), 'footer-basic' => array('files' => array('seowp-footer-default.xml.gz'), 'description' => __('Importing: Basic Footer...', 'lbmn')), 'basic-config' => array('description' => __('Final touches...', 'lbmn')), 'finish-basic-templates' => array('description' => __('Finishing...', 'lbmn')));
                // $files_to_import[] = $import_path . 'seowp-livecomposer-tutorials.xml.gz';
            }
            if ($_GET['importcontent'] == 'alldemocontent') {
                $import_path = $theme_dir . '/design/demo-content/';
                $files_array = array('start' => array(), 'home' => array('files' => array('seowp-homepages.xml.gz', 'seowp-predesignedpages-1.xml.gz'), 'description' => __('Importing: Home Page...', 'lbmn')), 'predesigned-1' => array('files' => array('seowp-predesignedpages-2.xml.gz', 'seowp-predesignedpages-3.xml.gz'), 'description' => __('Importing: Inner Pages – part 1...', 'lbmn')), 'predesigned-2' => array('files' => array('seowp-predesignedpages-4.xml.gz', 'seowp-predesignedpages-5.xml.gz'), 'description' => __('Importing: Inner Pages – part 2...', 'lbmn')), 'predesigned-3' => array('files' => array('seowp-predesignedpages-6.xml.gz', 'seowp-predesignedpages-7.xml.gz'), 'description' => __('Importing: Inner Pages – part 3...', 'lbmn')), 'predesigned-4' => array('files' => array('seowp-predesignedpages-8.xml.gz', 'seowp-predesignedpages-9.xml.gz'), 'description' => __('Importing: Inner Pages – part 4...', 'lbmn')), 'predesigned-5' => array('files' => array('seowp-predesignedpages-10.xml.gz', 'seowp-predesignedpages-11.xml.gz'), 'description' => __('Importing: Inner Pages – part 5...', 'lbmn')), 'downloads' => array('files' => array('seowp-downloads.xml.gz', 'seowp-partners.xml.gz'), 'description' => __('Importing: Resources & Partners...', 'lbmn')), 'staff' => array('files' => array('seowp-staff.xml.gz', 'seowp-testimonials.xml.gz'), 'description' => __('Importing: Staff & Testimonials...', 'lbmn')), 'posts' => array('files' => array('seowp-posts.xml.gz', 'seowp-projects.xml.gz'), 'description' => __('Importing: Posts & Projects...', 'lbmn')), 'media-home' => array('files' => array('seowp-media-homepage.xml.gz'), 'description' => __('Importing: Home Page – Images...', 'lbmn')), 'media-menu' => array('files' => array('seowp-media-menuimages.xml.gz'), 'description' => __('Importing: Menu – Images...', 'lbmn')), 'media-slider' => array('files' => array('seowp-media-sliderimages.xml.gz'), 'description' => __('Importing: Slider - Images...', 'lbmn')), 'media-clinentlogos' => array('files' => array('seowp-media-clientlogos.xml.gz'), 'description' => __('Importing: ClientLogos – Images...', 'lbmn')), 'media-blogthumbs' => array('files' => array('seowp-media-blogpostthumbs.xml.gz'), 'description' => __('Importing: Posts – Images...', 'lbmn')), 'media-footer' => array('files' => array('seowp-media-footerimages.xml.gz'), 'description' => __('Importing: Footer – Images...', 'lbmn')), 'media-staff' => array('files' => array('seowp-media-staffavatars.xml.gz'), 'description' => __('Importing: Staff – Images...', 'lbmn')), 'media-servicepage' => array('files' => array('seowp-media-servicepage.xml.gz'), 'description' => __('Importing: Services – Images...', 'lbmn')), 'media-bg' => array('files' => array('seowp-media-sectionbackgrounds.xml.gz'), 'description' => __('Importing: Background Images...', 'lbmn')), 'media-ebooks' => array('files' => array('seowp-media-ebookcovers.xml.gz'), 'description' => __('Importing E-book Covers...', 'lbmn')), 'media-projectthumbs' => array('files' => array('seowp-media-projectthumbs.xml.gz'), 'description' => __('Importing: Project – Images...', 'lbmn')), 'mainmenu' => array('files' => array('seowp-mainmenu.xml.gz'), 'description' => __('Importing: Main Menu...', 'lbmn')), 'menu-config' => array('description' => __('Configuring: Menus...', 'lbmn')), 'ninjaforms' => array('description' => __('Importing: Ninja Forms...', 'lbmn')), 'masterslider' => array('description' => __('Importing: Master Slider...', 'lbmn')), 'footers' => array('files' => array('seowp-themefooters.xml.gz'), 'description' => __('Importing: Theme Footers...', 'lbmn')), 'finish-maincontent' => array('description' => __('Finishing...', 'lbmn')));
            }
            if (isset($_GET['importcontent_step_current_id'])) {
                $content_part_id = sanitize_key($_GET['importcontent_step_current_id']);
                if (!$content_part_id) {
                    $content_part_id = 'start';
                }
                lbmn_debug_console($content_part_id);
                // Get array internal pointer to the poistion needed
                reset($files_array);
                while (key($files_array) !== $content_part_id && key($files_array) !== null) {
                    next($files_array);
                }
                if (key($files_array) === null) {
                    end($files_array);
                }
                $files_current = current($files_array);
                $files_current_id = key($files_array);
                $files_current_pos = array_search($files_current_id, array_keys($files_array));
                if (isset($files_array[$files_current_id]['files'])) {
                    // Prepare array of the files to import during the current step
                    foreach ($files_array[$files_current_id]['files'] as $file_name) {
                        $files_to_import[] = $import_path . $file_name;
                    }
                }
                // Transmit to the JS number of the current step and how many steps in total
                // to make possible to update the progress bar
                echo '<input type="hidden" name="importcontent_steps_total" id="importcontent_steps_total" value="' . count($files_array) . '" />';
                echo '<input type="hidden" name="importcontent_step_current_no" id="importcontent_step_current_no" value="' . $files_current_pos . '" />';
                echo '<input type="hidden" name="importcontent_step_current_descr" id="importcontent_step_current_descr" value="' . $files_array[$files_current_id]['description'] . '" />';
                // Set internal array pointer to the next position
                $files_next = next($files_array);
                $files_next_id = key($files_array);
                if (key($files_array) !== null) {
                    echo '<input type="hidden" name="importcontent_step_next_id" id="importcontent_step_next_id" value="' . $files_next_id . '" />';
                }
            }
            // Start Import
            if (file_exists($class_wp_importer)) {
                // Import included images
                $importer->fetch_attachments = true;
                foreach ($files_to_import as $import_file) {
                    if (is_file($import_file)) {
                        ob_start();
                        $importer->import($import_file);
                        $log = ob_get_contents();
                        ob_end_clean();
                        // output log in the hidden div
                        echo '<div class="ajax-log">';
                        echo $log;
                        echo '</div>';
                        if (stristr($log, 'error') || !stristr($log, 'All done.')) {
                            // Set marker div that will be fildered by ajax request
                            echo '<div class="ajax-request-error"></div>';
                            // output log in the div
                            echo '<div class="ajax-error-log">';
                            echo $log;
                            echo '</div>';
                        }
                    } else {
                        // Set marker div that will be fildered by ajax request
                        echo '<div class="ajax-request-error"></div>';
                        // output log in the div
                        echo '<div class="ajax-error-log">';
                        echo "Can't open file: " . $import_file . "</ br>";
                        echo '</div>';
                    }
                }
            } else {
                // Set marker div that will be fildered by ajax request
                echo '<div class="ajax-request-error"></div>';
                // output log in the div
                echo '<div class="ajax-error-log">';
                echo "Failed to load: " . $class_wp_import . "</ br>";
                echo '</div>';
            }
            // Set 'Organize my uploads into month- and year-based folders' setting
            // to its original state
            update_option('uploads_use_yearmonth_folders', $setting_original_useyearmonthfolders);
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'menu-topbar-config') {
            // Asign 'Demo Mega Menu' to the 'Header Menu' location
            $menu_object = wp_get_nav_menu_object('top-bar-menu');
            $menu_object_id = $menu_object->term_id;
            $locations = get_nav_menu_locations();
            $locations['topbar'] = $menu_object_id;
            set_theme_mod('nav_menu_locations', $locations);
            // Activate Mega Main Menu functionality for the 'header-menu' locations
            // See /inc/plugins-integration/megamainmenu.php for function source
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                lbmn_activate_mainmegamenu_locations();
            }
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'menu-basic-config') {
            // Asign 'Demo Mega Menu' to the 'Header Menu' location
            $menu_object = wp_get_nav_menu_object('basic-main-menu');
            $menu_object_id = $menu_object->term_id;
            $locations = get_nav_menu_locations();
            $locations['header-menu'] = $menu_object_id;
            set_theme_mod('nav_menu_locations', $locations);
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'menu-config') {
            // Asign 'Demo Mega Menu' to the 'Header Menu' location
            $menu_object = wp_get_nav_menu_object('mega-main-menu');
            $menu_object_id = $menu_object->term_id;
            $locations = get_nav_menu_locations();
            $locations['header-menu'] = $menu_object_id;
            set_theme_mod('nav_menu_locations', $locations);
            // Activate Mega Main Menu functionality for the 'header-menu' locations
            // See /inc/plugins-integration/megamainmenu.php for function source
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                lbmn_activate_mainmegamenu_locations();
            }
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'ninjaforms') {
            // Import Demo Ninja Forms
            lbmn_ninjaforms_import();
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'masterslider') {
            $import_path_demo_content = $theme_dir . '/design/demo-content/';
            // Import pre-designed MasterSlider Slides
            // Check if MasterSlider is active
            // http://support.averta.net/envato/support/ticket/regenerate-custom-css-programatically/#post-16478
            if (defined('MSWP_AVERTA_VERSION')) {
                $current_sliders = get_masterslider_names('title-id');
                $slider_already_imported = false;
                foreach ($current_sliders as $slider => $slider_id) {
                    if (stristr($slider, 'Flat Design Style')) {
                        $slider_already_imported = true;
                    }
                }
                if (!$slider_already_imported) {
                    global $ms_importer;
                    if (is_null($ms_importer)) {
                        $ms_importer = new MSP_Importer();
                    }
                    // * @return bool   true on success and false on failure
                    $slider_import_state = $ms_importer->import_data(file_get_contents($import_path_demo_content . 'seowp-masterslider.json'));
                }
                // Force Master Slider Custom CSS regeneration
                include_once MSWP_AVERTA_ADMIN_DIR . '/includes/msp-admin-functions.php';
                if (function_exists('msp_save_custom_styles')) {
                    msp_update_preset_css();
                    // Presets re-generation
                    msp_save_custom_styles();
                    // Save sliders custom css
                }
            }
        }
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'finish-maincontent') {
            // Use a static front page
            $home_page = get_page_by_title(LBMN_HOME_TITLE);
            update_option('page_on_front', $home_page->ID);
            update_option('show_on_front', 'page');
            // Set the blog page (not needed)
            // $blog = get_page_by_title( LBMN_BLOG_TITLE );
            // update_option( 'page_for_posts', $blog->ID );
            lbmn_debug_console('lbmn_customized_css_cache_reset');
            // Regenerate Custom CSS
            lbmn_customized_css_cache_reset(false);
            // refresh custom css without printig css (false)
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                // call the function that normally starts only in Theme Customizer
                lbmn_mainmegamenu_customizer_integration();
            }
        }
        /**
         * ----------------------------------------------------------------------
         * Basic configuration:
         * Post import actions
         */
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'basic-config') {
            // 1. Import Menus
            // 2. Activate Mega Main Menu for menu locations
            // 3. Import Widgets
            // 4. Demo description for author
            // 5. Tutorial Pages for LiveComposer
            // 6. Newsletter Sign-Up Plugin Settings
            // 7. Rotating Tweets Default Options Setup
            // 8. Regenerate Custom CSS
            // Path to the folder with basic import files
            $import_path_basic_config = $theme_dir . '/design/basic-config/';
            // $locations = get_nav_menu_locations();
            // set_theme_mod('nav_menu_locations', $locations);
            // 2: Activate Mega Main Menu for 'topbar' and 'header-menu' locations
            // See /inc/plugins-integration/megamainmenu.php for function source
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                lbmn_activate_mainmegamenu_locations();
            }
            // Predefine Custom Sidebars in LiveComposer
            // First set new sidebars in options table
            update_option('dslc_plugin_options_widgets_m', array('sidebars' => 'Sidebar,404 Page Widgets,Comment Form Area,'));
            // Define default Archive and Search options with System Templates
            // 404 Page Template
            $current_lc_archive_options = get_option('dslc_plugin_options_archives');
            $current_lc_archive_options['404_page'] = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_404_DEFAULT, 'lbmn_archive');
            // Archive Page Template
            $new_archive_listing_id = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_ARCHIVE_DEFAULT, 'lbmn_archive');
            $current_lc_archive_options['post'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_projects'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_galleries'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_downloads'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_staff'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_partners'] = $new_archive_listing_id;
            $current_lc_archive_options['author'] = $new_archive_listing_id;
            // Search Results
            $new_search_listing_id = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_SEARCHRESULTS_DEFAULT, 'lbmn_archive');
            $current_lc_archive_options['search_results'] = $new_search_listing_id;
            update_option('dslc_plugin_options_archives', $current_lc_archive_options);
            // Then run LiveComposer function that creates sidebars dynamically
            dslc_sidebars();
            // 3: Import widgets
            $files_with_widgets_to_import = array();
            $files_with_widgets_to_import[] = $import_path_basic_config . 'seowp-widgets.wie';
            // Remove default widgets from 'mobile-offcanvas' widget area
            $sidebars_widgets = get_option('sidebars_widgets');
            if (is_array($sidebars_widgets['mobile-offcanvas'])) {
                $sidebars_widgets['mobile-offcanvas'] = NULL;
            }
            update_option('sidebars_widgets', $sidebars_widgets);
            // There are dynamic values in 'seowp-widgets.wie' that needs to be replaced
            // before import processing
            global $widget_strings_replace;
            $widget_strings_replace = array('TOREPLACE_OFFCANVAS_MENUID' => lbmn_get_menuid_by_menutitle('Basic Main Menu'));
            foreach ($files_with_widgets_to_import as $file) {
                lbmn_import_data($file);
            }
            // 4: Put some demo description into current user info field
            // that used in the blog user boxes
            $user_ID = get_current_user_id();
            $user_info = get_userdata($user_ID);
            if (!$user_info->description) {
                update_user_meta($user_ID, 'description', 'This is author biographical info, ' . 'that can be used to tell more about you, your iterests, ' . 'background and experience. ' . 'You can change it on <a href="/wp-admin/profile.php">Admin &gt; Users &gt; Your Profile &gt; Biographical Info</a> page."');
            }
            // Add custom Mega Main Menu options
            $mmm_options = get_option('mega_main_menu_options');
            // Add custom Additional Mega Menu styles
            $mmm_options['additional_styles_presets'] = array('1' => array('style_name' => "Call to action item", 'text_color' => "rgba(255,255,255,1)", 'font' => array("font_size" => "15", "font_weight" => "600"), 'icon' => array("font_size" => "16"), 'bg_gradient' => array("color1" => "#A1C627", "start" => "0", "color2" => "#A1C627", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(255,255,255,1)", "bg_gradient_hover" => array("color1" => "#56AEE3", "start" => "0", "color2" => "#56AEE3", "end" => "100", "orientation" => "top")), '2' => array('style_name' => "Dropdown Heading", 'text_color' => "rgba(0,0,0,1)", 'font' => array("font_size" => "15", "font_weight" => "400"), 'icon' => array("font_size" => "15"), 'bg_gradient' => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(0,0,0,1)", "bg_gradient_hover" => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top")), '3' => array('style_name' => "Dropdown Menu Text", 'text_color' => "rgba(0,0,0,1)", 'icon' => array("font_size" => "21"), 'font' => array("font_size" => "21", "font_weight" => "300"), 'bg_gradient' => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(0,0,0,1)", "bg_gradient_hover" => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top")));
            // Add custom icons
            $mmm_options['set_of_custom_icons'] = array('1' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-spain.png')), '2' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-italy.png')), '3' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-france.png')), '4' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-uk.png')), '5' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-us.png')), '6' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-austria.png')), '7' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-belgium.png')), '8' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-germany.png')), '9' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-netherlands.png')), '10' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-poland.png')), '11' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-portugal.png')), '12' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-romania.png')), '13' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-russia.png')), '14' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-ukraine.png')));
            // Put Mega Main Menu options back
            update_option('mega_main_menu_options', $mmm_options);
            // 8: Regenerate Custom CSS
            lbmn_customized_css_cache_reset(false);
            // refresh custom css without printig css (false)
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                // call the function that normaly starts only in Theme Customizer
                lbmn_mainmegamenu_customizer_integration();
            }
        }
        // if $_GET['importcontent']
        // Update theme option '_basic_config_done'
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'finish-basic-templates') {
            update_option(LBMN_THEME_NAME . '_basic_config_done', true);
            define('LBMN_THEME_CONFUGRATED', true);
        }
        // Update theme option '_basic_config_done'
        if (isset($_GET['importcontent_step_current_id']) && $_GET['importcontent_step_current_id'] == 'finish-maincontent') {
            update_option(LBMN_THEME_NAME . '_democontent_imported', true);
        }
    }
    // is isset($_GET['importcontent'])
}
コード例 #3
0
function pvt_wordpress_content_importer()
{
    $theme_dir = get_template_directory();
    if (is_admin() && isset($_GET['importcontent'])) {
        if (!defined('WP_LOAD_IMPORTERS')) {
            define('WP_LOAD_IMPORTERS', true);
        }
        if (!class_exists('WP_Importer')) {
            $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
            if (file_exists($class_wp_importer)) {
                include $class_wp_importer;
            }
        }
        if (!class_exists('pvt_WP_Import')) {
            $class_wp_import = $theme_dir . '/inc/importer/wordpress-importer.php';
            if (file_exists($class_wp_import)) {
                include $class_wp_import;
            }
        }
        if (class_exists('WP_Importer') && class_exists('pvt_WP_Import')) {
            $importer = new pvt_WP_Import();
            $files_to_import = array();
            // Live Composer has links to images hard-coded, so before importing
            // media we need to check that the Settings > Media >
            // 'Organize my uploads into month- and year-based folders' unchecked
            // as on demo server. After import is done we set back original state
            // of this setting.
            $setting_original_useyearmonthfolders = get_option('uploads_use_yearmonth_folders');
            update_option('uploads_use_yearmonth_folders', 0);
            if ($_GET['importcontent'] == 'basic-templates') {
                $import_path = $theme_dir . '/design/basic-config/';
                $files_to_import[] = $import_path . 'seowp-templates.xml.gz';
                $files_to_import[] = $import_path . 'seowp-themefooters.xml.gz';
                $files_to_import[] = $import_path . 'seowp-systempagetemplates.xml.gz';
                $files_to_import[] = $import_path . 'seowp-livecomposer-tutorials.xml.gz';
            }
            if ($_GET['importcontent'] == 'alldemocontent') {
                $import_path = $theme_dir . '/design/demo-content/';
                $files_array = array(array('seowp-homepages.xml.gz', 'seowp-predesignedpages-1.xml.gz'), array('seowp-predesignedpages-2.xml.gz', 'seowp-predesignedpages-3.xml.gz'), array('seowp-predesignedpages-4.xml.gz', 'seowp-predesignedpages-5.xml.gz'), array('seowp-predesignedpages-6.xml.gz', 'seowp-predesignedpages-7.xml.gz'), array('seowp-predesignedpages-8.xml.gz', 'seowp-predesignedpages-9.xml.gz'), array('seowp-predesignedpages-10.xml.gz', 'seowp-predesignedpages-11.xml.gz'), array('seowp-downloads.xml.gz', 'seowp-partners.xml.gz'), array('seowp-staff.xml.gz', 'seowp-testimonials.xml.gz'), array('seowp-posts.xml.gz', 'seowp-projects.xml.gz'), array('seowp-media-homepage.xml.gz'), array('seowp-media-menuimages.xml.gz'), array('seowp-media-sliderimages.xml.gz'), array('seowp-media-clientlogos.xml.gz'), array('seowp-media-blogpostthumbs.xml.gz'), array('seowp-media-footerimages.xml.gz'), array('seowp-media-staffavatars.xml.gz'), array('seowp-media-servicepage.xml.gz'), array('seowp-media-sectionbackgrounds.xml.gz'), array('seowp-media-ebookcovers.xml.gz'), array('seowp-media-projectthumbs.xml.gz'));
                if (isset($_GET['importcontent_part'])) {
                    foreach ($files_array[$_GET['importcontent_part']] as $file_name) {
                        $files_to_import[] = $import_path . $file_name;
                    }
                    if (isset($files_array[$_GET['importcontent_part'] + 1])) {
                        echo '<input type="hidden" name="importcontent_part" id="importcontent_part" value="' . ($_GET['importcontent_part'] + 1) . '" />';
                    }
                }
            }
            // Start Import
            if (file_exists($class_wp_importer)) {
                // Import included images
                $importer->fetch_attachments = true;
                foreach ($files_to_import as $import_file) {
                    if (is_file($import_file)) {
                        ob_start();
                        $importer->import($import_file);
                        $log = ob_get_contents();
                        ob_end_clean();
                        // output log in the hidden div
                        echo '<div class="ajax-log">';
                        echo $log;
                        echo '</div>';
                        if (stristr($log, 'error') || !stristr($log, 'All done.')) {
                            // Set marker div that will be fildered by ajax request
                            echo '<div class="ajax-request-error"></div>';
                            // output log in the div
                            echo '<div class="ajax-error-log">';
                            echo $log;
                            echo '</div>';
                        }
                    } else {
                        // Set marker div that will be fildered by ajax request
                        echo '<div class="ajax-request-error"></div>';
                        // output log in the div
                        echo '<div class="ajax-error-log">';
                        echo "Can't open file: " . $import_file . "</ br>";
                        echo '</div>';
                    }
                }
            } else {
                // Set marker div that will be fildered by ajax request
                echo '<div class="ajax-request-error"></div>';
                // output log in the div
                echo '<div class="ajax-error-log">';
                echo "Failed to load: " . $class_wp_import . "</ br>";
                echo '</div>';
            }
            // Set 'Organize my uploads into month- and year-based folders' setting
            // to its original state
            update_option('uploads_use_yearmonth_folders', $setting_original_useyearmonthfolders);
        }
        /**
         * ----------------------------------------------------------------------
         * Basic configuration:
         * Post import actions
         */
        if ($_GET['importcontent'] == 'basic-templates') {
            // 1. Import Menus
            // 2. Activate Mega Main Menu for menu locations
            // 3. Import Widgets
            // 4. Demo description for author
            // 5. Tutorial Pages for LiveComposer
            // 6. Newsletter Sign-Up Plugin Settings
            // 7. Rotating Tweets Default Options Setup
            // 8. Regenerate Custom CSS
            // Path to the folder with basic import files
            $import_path_basic_config = $theme_dir . '/design/basic-config/';
            // 1:
            // Import Top Bar menu
            // if no menu set for 'topbar' location
            if (!has_nav_menu('topbar')) {
                if (is_plugin_active('wpfw_menus_management/wpfw_menus_management.php')) {
                    wpfw_import_menu($import_path_basic_config . 'seowp-menu-topbar.txt', 'topbar');
                }
            }
            // Import Mega Main Menu menu
            // if no menu set for 'header-menu' location
            if (!has_nav_menu('header-menu')) {
                if (is_plugin_active('wpfw_menus_management/wpfw_menus_management.php')) {
                    wpfw_import_menu($import_path_basic_config . 'seowp-menu-megamainmenu.txt', 'header-menu');
                }
            }
            $locations = get_nav_menu_locations();
            set_theme_mod('nav_menu_locations', $locations);
            // Import Mobile Off-Canvas Menu
            if (is_plugin_active('wpfw_menus_management/wpfw_menus_management.php')) {
                wpfw_import_menu($import_path_basic_config . 'seowp-menu-mobile-offcanvas.txt');
            }
            // 2: Activate Mega Main Menu for 'topbar' and 'header-menu' locations
            // See /inc/plugins-integration/megamainmenu.php for function source
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                lbmn_activate_mainmegamenu_locations();
            }
            // Predefine Custom Sidebars in LiveComposer
            // First set new sidebars in options table
            update_option('dslc_plugin_options_widgets_m', array('sidebars' => 'Sidebar,404 Page Widgets,Comment Form Area,'));
            // Define default Archive and Search options with System Templates
            // 404 Page Template
            $current_lc_archive_options = get_option('dslc_plugin_options_archives');
            $current_lc_archive_options['404_page'] = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_404_DEFAULT, 'lbmn_archive');
            // Archive Page Template
            $new_archive_listing_id = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_ARCHIVE_DEFAULT, 'lbmn_archive');
            $current_lc_archive_options['post'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_projects'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_galleries'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_downloads'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_staff'] = $new_archive_listing_id;
            $current_lc_archive_options['dslc_partners'] = $new_archive_listing_id;
            $current_lc_archive_options['author'] = $new_archive_listing_id;
            // Search Results
            $new_search_listing_id = lbmn_get_page_by_title(LBMN_SYSTEMPAGE_SEARCHRESULTS_DEFAULT, 'lbmn_archive');
            $current_lc_archive_options['search_results'] = $new_search_listing_id;
            update_option('dslc_plugin_options_archives', $current_lc_archive_options);
            // Then run LiveComposer function that creates sidebars dynamically
            dslc_sidebars();
            // 3: Import widgets
            $files_with_widgets_to_import = array();
            $files_with_widgets_to_import[] = $import_path_basic_config . 'seowp-widgets.wie';
            // Remove default widgets from 'mobile-offcanvas' widget area
            $sidebars_widgets = get_option('sidebars_widgets');
            if (is_array($sidebars_widgets['mobile-offcanvas'])) {
                $sidebars_widgets['mobile-offcanvas'] = NULL;
            }
            update_option('sidebars_widgets', $sidebars_widgets);
            // There are dynamic values in 'seowp-widgets.wie' that needs to be replaced
            // before import processing
            global $widget_strings_replace;
            $widget_strings_replace = array('TOREPLACE_OFFCANVAS_MENUID' => lbmn_get_menuid_by_menutitle('Mobile Off-canvas Menu'));
            foreach ($files_with_widgets_to_import as $file) {
                pvt_import_data($file);
            }
            // 4: Put some demo description into current user info field
            // that used in the blog user boxes
            $user_ID = get_current_user_id();
            $user_info = get_userdata($user_ID);
            if (!$user_info->description) {
                update_user_meta($user_ID, 'description', 'This is author biographical info, ' . 'that can be used to tell more about you, your iterests, ' . 'background and experience. ' . 'You can change it on <a href="/wp-admin/profile.php">Admin &gt; Users &gt; Your Profile &gt; Biographical Info</a> page."');
            }
            // 5: Predefine Tutorial Pages in LiveComposer
            update_option('dslc_plugin_options_tuts', array('lc_tut_chapter_one' => lbmn_get_page_by_slug('live-composer-tutorials/chapter-1'), 'lc_tut_chapter_two' => lbmn_get_page_by_slug('live-composer-tutorials/chapter-2'), 'lc_tut_chapter_three' => lbmn_get_page_by_slug('live-composer-tutorials/chapter-3'), 'lc_tut_chapter_four' => lbmn_get_page_by_slug('live-composer-tutorials/chapter-4')));
            // 6: Newsletter Sign-Up Plugin Form Elements
            update_option('nsu_form', array('email_label' => '', 'email_default_value' => 'Your email address...', 'email_label' => '', 'redirect_to' => get_site_url() . '/index.php?pagename=/lbmn_archive/thanks-for-signing-up/'));
            // Add custom Mega Main Menu options
            $mmm_options = get_option('mega_main_menu_options');
            // Add custom Additional Mega Menu styles
            $mmm_options['additional_styles_presets'] = array('1' => array('style_name' => "Call to action item", 'text_color' => "rgba(255,255,255,1)", 'font' => array("font_size" => "15", "font_weight" => "600"), 'icon' => array("font_size" => "16"), 'bg_gradient' => array("color1" => "#A1C627", "start" => "0", "color2" => "#A1C627", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(255,255,255,1)", "bg_gradient_hover" => array("color1" => "#56AEE3", "start" => "0", "color2" => "#56AEE3", "end" => "100", "orientation" => "top")), '2' => array('style_name' => "Dropdown Heading", 'text_color' => "rgba(0,0,0,1)", 'font' => array("font_size" => "15", "font_weight" => "400"), 'icon' => array("font_size" => "15"), 'bg_gradient' => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(0,0,0,1)", "bg_gradient_hover" => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top")), '3' => array('style_name' => "Dropdown Menu Text", 'text_color' => "rgba(0,0,0,1)", 'icon' => array("font_size" => "21"), 'font' => array("font_size" => "21", "font_weight" => "300"), 'bg_gradient' => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top"), "text_color_hover" => "rgba(0,0,0,1)", "bg_gradient_hover" => array("color1" => "", "start" => "0", "color2" => "", "end" => "100", "orientation" => "top")));
            // Add custom icons
            $mmm_options['set_of_custom_icons'] = array('1' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-spain.png')), '2' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-italy.png')), '3' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-france.png')), '4' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-uk.png')), '5' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-us.png')), '6' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-austria.png')), '7' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-belgium.png')), '8' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-germany.png')), '9' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-netherlands.png')), '10' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-poland.png')), '11' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-portugal.png')), '12' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-romania.png')), '13' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-russia.png')), '14' => array('custom_icon' => esc_url_raw(get_template_directory_uri() . '/images/flag-ukraine.png')));
            // Put Mega Main Menu options back
            update_option('mega_main_menu_options', $mmm_options);
            // 8: Regenerate Custom CSS
            lbmn_customized_css_cache_reset(false);
            // refresh custom css without printig css (false)
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                // call the function that normaly starts only in Theme Customizer
                lbmn_mainmegamenu_customizer_integration();
            }
        }
        // if $_GET['importcontent']
        /**
         * ----------------------------------------------------------------------
         * Demo Content: Full
         */
        if ($_GET['importcontent'] == 'alldemocontent' && $_GET['importcontent_part'] == 16) {
            $import_path_demo_content = $theme_dir . '/design/demo-content/';
            // Import Demo Ninja Forms
            lbmn_ninjaforms_import();
            lbmn_debug_console('Import Demo Mega Menu');
            // Import Demo Mega Menu menu
            if (is_plugin_active('wpfw_menus_management/wpfw_menus_management.php')) {
                wpfw_import_menu($import_path_demo_content . 'seowp-demomegamenu.txt', 'header-menu');
            }
            $locations = get_nav_menu_locations();
            set_theme_mod('nav_menu_locations', $locations);
            // Activate Mega Main Menu for 'header-menu' locations
            // See /inc/plugins-integration/megamainmenu.php for function source
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                lbmn_activate_mainmegamenu_locations();
            }
            // Import pre-designed MasterSlider Slides
            // Check if MasterSlider is active
            // http://support.averta.net/envato/support/ticket/regenerate-custom-css-programatically/#post-16478
            if (defined('MSWP_AVERTA_VERSION')) {
                $current_sliders = get_masterslider_names('title-id');
                $slider_already_imported = false;
                foreach ($current_sliders as $slider => $slider_id) {
                    if (stristr($slider, 'Flat Design Style')) {
                        $slider_already_imported = true;
                    }
                }
                if (!$slider_already_imported) {
                    global $ms_importer;
                    if (is_null($ms_importer)) {
                        $ms_importer = new MSP_Importer();
                    }
                    // * @return bool   true on success and false on failure
                    $slider_import_state = $ms_importer->import_data(file_get_contents($import_path_demo_content . 'seowp-masterslider.json'));
                }
                // Force Master Slider Custom CSS regeneration
                include_once MSWP_AVERTA_ADMIN_DIR . '/includes/msp-admin-functions.php';
                if (function_exists('msp_save_custom_styles')) {
                    msp_update_preset_css();
                    // Presets re-generation
                    msp_save_custom_styles();
                    // Save sliders custom css
                }
            }
            // Use a static front page
            $home_page = get_page_by_title(LBMN_HOME_TITLE);
            update_option('page_on_front', $home_page->ID);
            update_option('show_on_front', 'page');
            // Set the blog page (not needed)
            // $blog = get_page_by_title( LBMN_BLOG_TITLE );
            // update_option( 'page_for_posts', $blog->ID );
            lbmn_debug_console('lbmn_customized_css_cache_reset');
            // Regenerate Custom CSS
            lbmn_customized_css_cache_reset(false);
            // refresh custom css without printig css (false)
            if (is_plugin_active('mega_main_menu/mega_main_menu.php')) {
                // call the function that normally starts only in Theme Customizer
                lbmn_mainmegamenu_customizer_integration();
            }
            // lbmn_debug_console( 'Search & Replace image URLS' );
            // Search & Replace image URLS
            // lbmn_lcsearchreplace(); not needed any more
        }
        // if $_GET['importcontent']
    }
    // is isset($_GET['importcontent'])
}
コード例 #4
0
ファイル: importer.php プロジェクト: booklein/wpbookle
function porto_import()
{
    global $wpdb, $porto_settings;
    if (current_user_can('manage_options') && isset($_GET['page']) && $_GET['page'] == 'porto_settings') {
        if (isset($_GET['import_sample_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 = porto_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
                // update visual composer content types
                update_option('wpb_js_content_types', array('post', 'page', 'block', 'faq', 'member', 'portfolio'));
                $importer = new WP_Import();
                // update woocommerce image sizes
                $catalog = array('width' => '300', 'height' => '400', 'crop' => 1);
                $single = array('width' => '500', 'height' => '666', 'crop' => 1);
                $thumbnail = array('width' => '90', 'height' => '90', 'crop' => 1);
                // Image sizes
                add_image_size('shop_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop']);
                add_image_size('shop_catalog', $catalog['width'], $catalog['height'], $catalog['crop']);
                add_image_size('shop_single', $single['width'], $single['height'], $single['crop']);
                $theme_xml = porto_plugins . '/importer/data/dummy_data.xml';
                $importer->fetch_attachments = true;
                ob_start();
                $importer->import($theme_xml);
                ob_end_clean();
                // Set woocommerce pages
                $woopages = array('woocommerce_shop_page_id' => 'Shop', 'woocommerce_cart_page_id' => 'Cart', 'woocommerce_checkout_page_id' => 'Checkout', 'woocommerce_myaccount_page_id' => 'My Account');
                foreach ($woopages as $woo_page_name => $woo_page_title) {
                    $woopage = get_page_by_title($woo_page_title);
                    if (isset($woopage) && $woopage->ID) {
                        update_option($woo_page_name, $woopage->ID);
                        // Front Page
                    }
                }
                // We no longer need to install pages
                $notices = array_diff(get_option('woocommerce_admin_notices', array()), array('install', 'update'));
                update_option('woocommerce_admin_notices', $notices);
                delete_option('_wc_needs_pages');
                delete_transient('_wc_activation_redirect');
                // 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 Menu') {
                            $locations['main_menu'] = $menu->term_id;
                        } else {
                            if ($menu->name == 'Top Navigation') {
                                $locations['top_nav'] = $menu->term_id;
                            } else {
                                if ($menu->name == 'View Switcher') {
                                    $locations['view_switcher'] = $menu->term_id;
                                } else {
                                    if ($menu->name == 'Currency Switcher') {
                                        $locations['currency_switcher'] = $menu->term_id;
                                    }
                                }
                            }
                        }
                    }
                }
                set_theme_mod('nav_menu_locations', $locations);
                // set menus to locations
                // Set reading options
                $homepage = get_page_by_title('Home');
                $posts_page = get_page_by_title('Blog');
                if ($homepage && $homepage->ID || $posts_page && $posts_page->ID) {
                    update_option('show_on_front', 'page');
                    if ($homepage && $homepage->ID) {
                        update_option('page_on_front', $homepage->ID);
                        // Front Page
                    }
                    if ($posts_page && $posts_page->ID) {
                        update_option('page_for_posts', $posts_page->ID);
                        // Blog Page
                    }
                }
                // Add sidebar widget areas
                $sidebars = array('Shortcodes' => 'Shortcodes');
                update_option('sbg_sidebars', $sidebars);
                flush_rewrite_rules();
                // finally redirect to success page
                wp_redirect(admin_url('admin.php?page=porto_settings&import_success=true'));
            }
        }
        if (isset($_GET['import_masterslider'])) {
            // Import master sliders
            if (class_exists('MSP_Importer')) {
                $slider_alias = get_masterslider_names('alias');
                for ($i = 1; $i < PORTO_MASTERSLIDER_COUNT; $i++) {
                    if (isset($slider_alias['ms-' . $i]) && $slider_alias['ms-' . $i]) {
                    } else {
                        ob_start();
                        include porto_plugins . '/importer/data/master_slider_' . $i . '.json';
                        $master_slider_data = ob_get_clean();
                        $master_slider_importer = new MSP_Importer();
                        ob_start();
                        $master_slider_importer->import_data($master_slider_data);
                        ob_end_clean();
                    }
                }
            }
            flush_rewrite_rules();
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&import_masterslider_success=true'));
        }
        if (isset($_GET['import_font'])) {
            if (get_option('smile_fonts', false)) {
                // Import Simple Line Icon Font
                $paths = wp_upload_dir();
                $paths['fonts'] = 'smile_fonts';
                $paths['temp'] = trailingslashit($paths['fonts']) . 'smile_temp';
                $paths['fontdir'] = trailingslashit($paths['basedir']) . $paths['fonts'];
                $paths['tempdir'] = trailingslashit($paths['basedir']) . $paths['temp'];
                $paths['fonturl'] = set_url_scheme(trailingslashit($paths['baseurl']) . $paths['fonts']);
                $paths['tempurl'] = trailingslashit($paths['baseurl']) . trailingslashit($paths['temp']);
                $paths['config'] = 'charmap.php';
                $sli_fonts = trailingslashit($paths['basedir']) . $paths['fonts'] . '/Simple-Line-Icons';
                $sli_fonts_dir = porto_plugins . '/importer/data/Simple-Line-Icons/';
                // Make destination directory
                if (!is_dir($sli_fonts)) {
                    wp_mkdir_p($sli_fonts);
                }
                @chmod($sli_fonts, 0777);
                foreach (glob($sli_fonts_dir . '*') as $file) {
                    $new_file = basename($file);
                    @copy($file, $sli_fonts . '/' . $new_file);
                }
                $fonts = get_option('smile_fonts');
                if (empty($fonts)) {
                    $fonts = array();
                }
                $fonts['Simple-Line-Icons'] = array('include' => trailingslashit($paths['fonts']) . 'Simple-Line-Icons', 'folder' => trailingslashit($paths['fonts']) . 'Simple-Line-Icons', 'style' => 'Simple-Line-Icons' . '/' . 'Simple-Line-Icons' . '.css', 'config' => $paths['config']);
                update_option('smile_fonts', $fonts);
                flush_rewrite_rules();
                // finally redirect to success page
                wp_redirect(admin_url('admin.php?page=porto_settings&import_font_success=true'));
            } else {
                flush_rewrite_rules();
                // finally redirect to success page
                wp_redirect(admin_url('admin.php?page=porto_settings&import_font_success=false'));
            }
        }
        if (isset($_GET['import_widget'])) {
            // Import widgets
            ob_start();
            include porto_plugins . '/importer/data/widget_data.json';
            $widget_data = ob_get_clean();
            porto_import_widget_data($widget_data);
            flush_rewrite_rules();
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&import_widget_success=true'));
        }
        if (isset($_GET['import_theme_options'])) {
            $demo = $_GET['import_theme_options'];
            ob_start();
            include porto_plugins . '/importer/data/theme_options' . $demo . '.php';
            $theme_options = ob_get_clean();
            $options = json_decode($theme_options, true);
            $redux = ReduxFrameworkInstances::get_instance('porto_settings');
            $redux->set_options($options);
            porto_compile_css(true);
            porto_save_theme_settings();
            // Set reading options
            if (!$demo) {
                $page_title = 'Home';
            } else {
                if ($demo == '_rtl') {
                    $page_title = 'Home RTL Version';
                } else {
                    $page_title = 'Home Version ' . str_replace('_', '', $demo);
                }
            }
            $homepage = get_page_by_title($page_title);
            $posts_page = get_page_by_title('Blog');
            if ($homepage && $homepage->ID || $posts_page && $posts_page->ID) {
                update_option('show_on_front', 'page');
                if ($homepage && $homepage->ID) {
                    update_option('page_on_front', $homepage->ID);
                    // Front Page
                }
                if ($posts_page && $posts_page->ID) {
                    update_option('page_for_posts', $posts_page->ID);
                    // Blog Page
                }
            }
            flush_rewrite_rules();
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&import_options_success=true'));
        }
    }
}