Example #1
0
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();
                // 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');
                } 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
                // Set reading options
                $homepage = get_page_by_title('Home Version 1');
                $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')) {
                for ($i = 1; $i < 11; $i++) {
                    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_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 Version 1';
            } 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'));
        }
    }
}
Example #2
0
<?php

/**
 * Porto Theme Options
 */
require_once porto_admin . '/functions.php';
// include redux framework core functions
require_once porto_admin . '/ReduxCore/framework.php';
// porto theme settings options
require_once porto_admin . '/porto/settings.php';
require_once porto_admin . '/porto/save_settings.php';
if (get_option('porto_init_theme', '0') != '1') {
    porto_check_theme_options();
}
// regenerate default css, skin css files after update theme
$porto_cur_version = get_option('porto_version', '1.0');
if (!porto_is_ajax() && version_compare(porto_version, $porto_cur_version, '>') && version_compare(phpversion(), '5.3', '>=')) {
    update_option('porto_version', porto_version);
    @ini_set('max_execution_time', '10000');
    @ini_set('memory_limit', '256M');
    // regenerate default css
    if (file_exists(porto_dir . '/css/plugins_rtl_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/plugins_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_rtl_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_rtl_shop_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_shop_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_rtl_bbpress_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/theme_bbpress_' . porto_get_blog_id() . '.css')) {
        porto_compile_css(true);
    }
    // regenerate skin css
    if (file_exists(porto_dir . '/css/skin_rtl_' . porto_get_blog_id() . '.css') || file_exists(porto_dir . '/css/skin_' . porto_get_blog_id() . '.css')) {
        porto_save_theme_settings();
    }
}
update_option('porto_version', porto_version);