/** * Function that imports selected demo content (with options & widgets) * into a WordPress install. * * Needs to be passed the selected demo content pack as an argument. */ function quadro_dcontent_importx($pack) { global $wpdb, $quadro_options_group, $quadro_options; // Bring Available Demo Content Packs $dcontent_packs = qi_available_demo_packs(); $dcontent_path = $dcontent_packs[$pack]['path']; $dcontent_file = $dcontent_packs[$pack]['file']; $dcontent_settings = $dcontent_packs[$pack]['settings']; $dcontent_widgets = $dcontent_packs[$pack]['widgets']; $dcontent_reading = $dcontent_packs[$pack]['reading']; $dcontent_front = $dcontent_packs[$pack]['front']; $dcontent_posts = $dcontent_packs[$pack]['posts']; $dcontent_plugins = $dcontent_packs[$pack]['plugins']; // Before we start, check if user has permissions if (current_user_can('manage_options')) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } // Ensure WordPress Importer Class if (!class_exists('WP_Importer')) { require ABSPATH . 'wp-admin/includes/class-wp-importer.php'; } // Deactivate WP Importer Plugin (to eliminate false "falses") deactivate_plugins('/wordpress-importer/wordpress-importer.php', true); // Ensure WordPress Importer Plugin if (!class_exists('WP_Import')) { require get_template_directory() . '/inc/qi-framework/wordpress-importer.php'; } // With both of them loaded if (class_exists('WP_Importer') && class_exists('WP_Import')) { $dcontent = new WP_Import(); // Basic dummy content import $theme_xml = get_template_directory() . '/inc/dcontent/' . $dcontent_path . $dcontent_file; $dcontent->fetch_attachments = true; ob_start(); $dcontent->import($theme_xml); ob_end_clean(); // Set Menu locations for imported menus $locations = get_theme_mod('nav_menu_locations'); $menus = wp_get_nav_menus(); if ($menus) { foreach ($menus as $menu) { if ($menu->name == 'Main Menu') { // This name should be taken from the demo $locations['primary'] = $menu->term_id; $locations['secondary'] = $menu->term_id; } elseif ($menu->name == 'Short') { // This name should be taken from the demo // $locations['secondary'] = $menu->term_id; } } } set_theme_mod('nav_menu_locations', $locations); // Import Theme Options $theme_options_file = get_template_directory_uri() . '/inc/dcontent/' . $dcontent_path . $dcontent_settings; $theme_options_file = wp_remote_get($theme_options_file); $data = unserialize(urldecode($theme_options_file['body'])); // Preserve User's Sensitive Options $data['quadro_username'] = $quadro_options['quadro_username']; $data['quadro_userpass'] = $quadro_options['quadro_userpass']; $data['quadro_userlicense'] = $quadro_options['quadro_userlicense']; $data['typekit_kit_id'] = $quadro_options['typekit_kit_id']; // Set value to let the validation callback know // it is alright to go through all the options. $data['restore_next'] = true; update_option($quadro_options_group, $data); // Retrieve sidebars from import quadro_widgets_init(); // Add data to widgets $widgets_json = get_template_directory_uri() . '/inc/dcontent/' . $dcontent_path . $dcontent_widgets; $widgets_json = wp_remote_get($widgets_json); $widget_data = $widgets_json['body']; $import_widgets = quadro_import_widget_data($widget_data); /** * Set reading options */ $homepage = get_page_by_title($dcontent_front); $posts_page = get_page_by_title($dcontent_posts); update_option('show_on_front', $dcontent_reading); if ($homepage->ID) { update_option('page_on_front', $homepage->ID); } if ($posts_page->ID) { update_option('page_for_posts', $posts_page->ID); } // That's it! Go back to options-helper.php and then return to ajax call. die; } } }
/** * Ajax Demo Content Import Functions * Adapted from: https://github.com/syamilmj/Options-Framework */ function quadro_ajax_dcontent() { // Check nonce $nonce = $_POST['security']; if (!wp_verify_nonce($nonce, 'quadro_ajax_nonce')) { die('-1'); } $call_type = esc_attr($_POST['type']); if ($call_type == 'dcontent_details') { // Bring Available Demo Content Packs $dcontent_packs = qi_available_demo_packs(); // Retrieve selected pack $pack = esc_attr($_POST['pack']); echo '<a href="#" class="backto-dcontent">' . esc_html__('Back to Packs', 'quadro') . '</a>'; echo '<div class="dcontent-text">'; echo '<h3>' . $dcontent_packs[$pack]['name'] . '</h3>'; echo '<p class="dcontent-desc">' . $dcontent_packs[$pack]['desc'] . '</p>'; echo '<p class="dcontent-tags">' . $dcontent_packs[$pack]['tags'] . '</p>'; echo '<p class="dcontent-plugins"><span>Plugins being used:</span> '; $plugins_used = ''; foreach ($dcontent_packs[$pack]['plugins'] as $key => $value) { $plugins_used .= $value . ', '; } echo rtrim($plugins_used, ', '); echo '</p>'; echo '<small>' . esc_html__('* Images are not included', 'quadro') . '</small>'; echo '<div>'; echo '<a href="' . $dcontent_packs[$pack]['url'] . '" class="dcontent-demo-link" target="_blank">' . esc_html__('View Online Demo', 'quadro') . '</a>'; echo '<a href="#" class="dcontent-install-pack" data-pack="' . $dcontent_packs[$pack]['slug'] . '">' . esc_html__('Install This Pack', 'quadro') . '</a>'; echo '<i class="fa fa-cog fa-spin fa-2x fa-fw dpack-loader" style="display: none;"></i>'; echo '</div>'; echo '</div>'; echo '<div class="dcontent-gallery">'; echo '<div class="dcontent-thumb-screener">'; echo '<img src="' . get_template_directory_uri() . '/inc/dcontent/' . $dcontent_packs[$pack]['path'] . $dcontent_packs[$pack]['thumbs'][0] . '">'; echo '</div>'; echo '<ul class="dcontent-thumbs">'; foreach ($dcontent_packs[$pack]['thumbs'] as $thumb) { echo '<img src="' . get_template_directory_uri() . '/inc/dcontent/' . $dcontent_packs[$pack]['path'] . $thumb . '">'; } echo '</ul>'; echo '</div>'; die; } elseif ($call_type == 'dcontent_importx') { // Include Dummy Content Importer functions require get_template_directory() . '/inc/qi-framework/dcontent_importerx.php'; // Run Dummy Content Import functions quadro_dcontent_importx(esc_attr($_POST['pack'])); die('1'); } die; }