function tallybuilder_admin_action_import_page() { if (isset($_POST['tallybuilder_import_page_field'])) { if (wp_verify_nonce($_POST['tallybuilder_import_page_field'], 'tallybuilder_import_page_action')) { if (isset($_POST['page_import_data']) && $_POST['page_import_data'] != '') { $page_import = tallybuilder_import_page_from_array(unserialize(tallybuilder_decode($_POST['page_import_data']))); if ($page_import > 1) { $page_edit_url = esc_url(admin_url('admin.php?page=tallybuilder&view=sections&tallybuilder_page_id=' . $page_import)); echo '<div id="message" class="updated notice notice-success is-dismissible">'; echo '<p>' . __('New Page Created.', 'tally-builder') . ' <a href="' . $page_edit_url . '">' . __('Edit it Now', 'tally-builder') . '</a></p>'; echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>'; echo '</div>'; } } } else { _e('Sorry, your nonce did not verify.', 'tally-builder'); } } }
function tallythemesetup_demo_import() { $disable_xml_import = apply_filters('tallythemesetup_disable_xml_import', false); $disable_wie_import = apply_filters('tallythemesetup_disable_wie_import', false); $disable_menu_setup = apply_filters('tallythemesetup_disable_menu_setup', false); $disable_home_setup = apply_filters('tallythemesetup_disable_home_setup', false); $disable_blog_setup = apply_filters('tallythemesetup_disable_blog_setup', false); $disable_builder_import = apply_filters('tallythemesetup_disable_builder_import', false); $disable_config_file = get_template_directory() . "/inc/demo/disable-config.php"; if (file_exists($disable_config_file)) { include $disable_config_file; } /* 1. XML importer ------------------------------------------------------------------*/ if ($_REQUEST['target'] == 'xml_import' && $disable_xml_import == false) { if (!defined('WP_LOAD_IMPORTERS')) { define('WP_LOAD_IMPORTERS', true); } include 'inc/WXR-parsers.php'; include 'inc/import-xml.php'; if (class_exists('tallythemesetup_import')) { $content_xml_child = get_stylesheet_directory() . "/inc/demo/content.xml"; $content_xml_theme = get_template_directory() . "/inc/demo/content.xml"; $content_alt_xml_child = get_stylesheet_directory() . "/inc/demo/content-alt.xml"; $content_alt_xml_theme = get_template_directory() . "/inc/demo/content-alt.xml"; if (file_exists($content_xml_child)) { $import_filepath = $content_xml_child; } elseif (file_exists($content_xml_theme)) { $import_filepath = $content_xml_theme; } elseif (file_exists($content_alt_xml_child)) { $import_filepath = $content_alt_xml_child; } else { $import_filepath = $content_alt_xml_theme; } if (file_exists($import_filepath)) { $WP_Import = new tallythemesetup_import(); $WP_Import->fetch_attachments = true; set_time_limit(0); ob_start(); $WP_Import->import($import_filepath); $log = ob_get_contents(); ob_end_clean(); if ($WP_Import->check()) { echo 'Sample contents are imported.'; //echo $log; update_option(TALLYTHEMESETUP_IS_XML, 'yes'); } } else { echo 'No XML file found in the theme.'; echo $import_filepath; } } } elseif ($_REQUEST['target'] == 'xml_import' && $disable_xml_import == true) { update_option(TALLYTHEMESETUP_IS_XML, 'yes'); } /* 2. Widget importer ------------------------------------------------------------------*/ if ($_REQUEST['target'] == 'widget_import' && $disable_wie_import == false) { if (!function_exists('tallythemesetup_process_widget_data')) { require_once 'inc/import-widgets-wie.php'; } if (function_exists('tallythemesetup_process_widget_data')) { $widget_file_child = get_stylesheet_directory() . "/inc/demo/widgets.wie"; $widget_file_theme = get_template_directory() . "/inc/demo/widgets.wie"; $widget_alt_file_child = get_stylesheet_directory() . "/inc/demo/widgets-alt.wie"; $widget_alt_file_theme = get_template_directory() . "/inc/demo/widgets-alt.wie"; if (file_exists($widget_file_child)) { $wie_filepath = $widget_file_child; } elseif (file_exists($widget_file_theme)) { $wie_filepath = $widget_file_theme; } elseif (file_exists($widget_alt_file_child)) { $wie_filepath = $widget_alt_file_child; } else { $wie_filepath = $widget_alt_file_theme; } if (file_exists($wie_filepath)) { if (tallythemesetup_process_widget_data($wie_filepath)) { echo 'Sample Widgets are imported.'; update_option(TALLYTHEMESETUP_IS_WIDGET, 'yes'); } } else { echo 'No widgets.wie file found in the theme'; } } } elseif ($_REQUEST['target'] == 'widget_import' && $disable_wie_import == true) { update_option(TALLYTHEMESETUP_IS_WIDGET, 'yes'); } /* 3. Setup Home page as front page ------------------------------------------------------------------*/ if ($_REQUEST['target'] == 'setup_home') { $home_page_title = apply_filters('tallythemesetup_home_title', 'Home'); $blog_page_title = apply_filters('tallythemesetup_blog_title', 'Blog'); $reading_config_file = get_template_directory() . "/inc/demo/reading-config.php"; if (file_exists($reading_config_file)) { include $reading_config_file; } $home_page_data = get_page_by_title($home_page_title); $home_blog_data = get_page_by_title($blog_page_title); $text_content = ''; if ($home_page_data) { if (update_option('page_on_front', $home_page_data->ID) && $disable_home_setup == false) { update_option('show_on_front', 'page'); $text_content .= 'Set home page as Front page. <br>'; update_option(TALLYTHEMESETUP_IS_HOME, 'yes'); } } if ($home_blog_data) { if (update_option('page_for_posts', $home_blog_data->ID) && $disable_blog_setup == false) { $text_content .= '<br>Set Blog page as Post page.'; update_option(TALLYTHEMESETUP_IS_BLOG, 'yes'); } } echo $text_content; } if ($disable_home_setup == true) { update_option(TALLYTHEMESETUP_IS_HOME, 'yes'); } if ($disable_blog_setup == true) { update_option(TALLYTHEMESETUP_IS_BLOG, 'yes'); } /* 4. Setup the menu ------------------------------------------------------------------*/ if ($_REQUEST['target'] == 'setup_menu' && $disable_menu_setup == false) { $menu_config_file = get_template_directory() . "/inc/demo/menu-config.php"; if (file_exists($menu_config_file)) { include $menu_config_file; echo 'Setting Up WordPress Menu'; update_option(TALLYTHEMESETUP_IS_MENU, 'yes'); } else { $selected_menu_name = apply_filters('tallythemesetup_menu_slug', 'primary'); $selected_menu_location = apply_filters('tallythemesetup_menu_location', 'primary'); $menu_term_id = ''; $get_all_menu = get_terms('nav_menu', array('hide_empty' => true)); if (!empty($get_all_menu) && !is_wp_error($get_all_menu)) { foreach ($get_all_menu as $the_menu) { if ($the_menu->slug == $selected_menu_name) { $menu_term_id = $the_menu->term_id; } } } $locations = get_theme_mod('nav_menu_locations'); $locations[$selected_menu_location] = $menu_term_id; //$foo is term_id of menu set_theme_mod('nav_menu_locations', $locations); if ($locations[$selected_menu_location] == $menu_term_id) { echo 'Set primary menu as site menu.'; update_option(TALLYTHEMESETUP_IS_MENU, 'yes'); } } } elseif ($_REQUEST['target'] == 'setup_menu' && $disable_menu_setup == true) { update_option(TALLYTHEMESETUP_IS_MENU, 'yes'); } /* 5. Import Builder pages ------------------------------------------------------------------*/ if ($_REQUEST['target'] == 'builder_import' && $disable_builder_import == false) { if (function_exists('tallybuilder_import_page_from_array')) { $pages_list = apply_filters('tallybuilder_prebuild_pages', NULL); if (is_array($pages_list)) { foreach ($pages_list as $page) { if (file_exists($page['file'])) { include $page['file']; tallybuilder_import_page_from_array($page_data); } } } update_option(TALLYTHEMESETUP_IS_BUILDER, 'yes'); echo 'Builder content imported'; } else { echo '<strong>Could not import builder content.</strong> Please Install the Builder Plugin'; } } elseif ($_REQUEST['target'] == 'builder_import' && $disable_builder_import == true) { update_option(TALLYTHEMESETUP_IS_BUILDER, 'yes'); } if ($_REQUEST['target'] == 'update_option') { echo '<p style="font-size:18px; color:#0A9900;">All Done</p>'; } die; // this is required to return a proper result }