File: /home/xedaptot/naniguide.com/wp-content/plugins/golo-framework/includes/class-golo-importer.php
<?php
class Golo_Framework_Importer {
public function __construct() {
add_filter( 'ocdi/import_files', [ $this, 'import_files' ] );
add_action( 'ocdi/after_import', [ $this, 'golo_after_import_setup' ] );
add_filter( 'ocdi/plugin_intro_text', [ $this, 'ocdi_plugin_intro_text' ] );
add_filter( 'ocdi/plugin_page_setup', [ $this, 'ocdi_plugin_page_setup' ] );
}
function ocdi_plugin_page_setup( $default_settings ) {
$default_settings['parent_slug'] = 'themes.php';
$default_settings['page_title'] = esc_html__( 'Import' , 'one-click-demo-import' );
$default_settings['menu_title'] = esc_html__( 'Import Demo' , 'one-click-demo-import' );
$default_settings['capability'] = 'import';
$default_settings['menu_slug'] = 'one-click-demo-import';
return $default_settings;
}
public function import_files() {
return [
[
'import_file_name' => 'City Guide',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/01/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/01/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/01/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/01/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/city-guide',
],
[
'import_file_name' => 'Bussiness Listing',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/02/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/02/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/02/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/02/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/business-listing',
],
[
'import_file_name' => 'Country Travel Guide',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/03/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/03/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/03/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/03/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/country-guide',
],
[
'import_file_name' => 'Restaurant Listing',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/04/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/04/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/04/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/04/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/restaurant',
],
[
'import_file_name' => 'Workspace',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/05/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/05/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/05/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/05/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/workspace',
],
[
'import_file_name' => 'Health-Medical',
'import_file_url' => GOLO_PLUGIN_URL . 'assets/import/06/content.xml',
'import_widget_file_url' => GOLO_PLUGIN_URL . 'assets/import/06/widgets.json',
'import_customizer_file_url' => GOLO_PLUGIN_URL . 'assets/import/06/customizer.dat',
'import_preview_image_url' => GOLO_PLUGIN_URL . 'assets/import/06/screenshot.png',
'import_notice' => __( 'After importing this demo, please go to Settings > Permalinks and click "Save Changes" to update your permalink structure.', 'your-textdomain' ),
'preview_url' => 'https://wp.getgolo.com/health-medical',
],
];
}
public function golo_after_import_setup( $selected_import ) {
$listing_menu = get_term_by( 'name', 'Listing Menu', 'nav_menu' );
$canvas_menu = get_term_by( 'name', 'Canvas Menu', 'nav_menu' );
$import_name = $selected_import['import_file_name'] ?? '';
if ( in_array( $import_name, [ 'Restaurant Listing', 'Workspace', 'Health-Medical' ] ) ) {
$canvas_menu = get_term_by( 'name', 'Off Canvas', 'nav_menu' );
}
$menu_locations = [];
if ( $import_name === 'Country Travel Guide' ) {
if ( $listing_menu ) {
$menu_locations['main_menu'] = $listing_menu->term_id;
}
if ( $canvas_menu ) {
$menu_locations['mobile_menu'] = $canvas_menu->term_id;
}
} elseif ( in_array( $import_name, [ 'Bussiness Listing', 'Restaurant Listing', 'Workspace', 'Health-Medical' ] ) ) {
if ( $listing_menu ) {
$menu_locations['primary'] = $listing_menu->term_id;
$menu_locations['main_menu'] = $listing_menu->term_id;
}
if ( $canvas_menu ) {
$menu_locations['mobile_menu'] = $canvas_menu->term_id;
}
} elseif ( $import_name === 'City Guide' ) {
if ( $listing_menu ) {
$menu_locations['main_menu'] = $listing_menu->term_id;
}
if ( $canvas_menu ) {
$menu_locations['mobile_menu'] = $canvas_menu->term_id;
$menu_locations['primary'] = $canvas_menu->term_id;
}
}
if ( ! empty( $menu_locations ) ) {
set_theme_mod( 'nav_menu_locations', $menu_locations );
}
$front_page_title = ( $import_name === 'Restaurant Listing' ) ? 'Home Default' : 'Home';
$front_page = get_page_by_title( $front_page_title );
$blog_page = get_page_by_title( 'Blog' );
if ( $front_page && $blog_page ) {
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $front_page->ID );
update_option( 'page_for_posts', $blog_page->ID );
}
$pages = [
'golo_submit_place_page_id' => $this->get_page_id_by_title( 'New Place' ),
'golo_my_places_page_id' => $this->get_page_id_by_title( 'My Places' ),
'golo_my_profile_page_id' => $this->get_page_id_by_title( 'My Profile' ),
'golo_my_wishlist_page_id' => $this->get_page_id_by_title( 'My Wishlist' ),
'golo_bookings_page_id' => $this->get_page_id_by_title( 'Bookings' ),
'golo_dashboard_page_id' => $this->get_page_id_by_title( 'Dashboard' ),
'golo_packages_page_id' => $this->get_page_id_by_title( 'Packages' ),
'golo_payment_page_id' => $this->get_page_id_by_title( 'Payment' ),
'golo_payment_completed_page_id'=> $this->get_page_id_by_title( 'Payment Completed' ),
];
update_option( GOLO_OPTIONS_NAME, $pages );
$this->ocdi_create_and_activate_child_theme();
}
public function get_page_id_by_title( $title ) {
$page = get_page_by_title( $title );
return $page ? $page->ID : 0;
}
public function ocdi_create_and_activate_child_theme() {
$child_slug = 'golo-child';
$child_dir = get_theme_root() . '/' . $child_slug;
if (!file_exists($child_dir)) {
mkdir($child_dir, 0755, true);
$parent_theme = wp_get_theme()->get_template();
$style = <<<CSS
/*
Theme Name: Golo Child
Theme URI: https://wp.getgolo.com/
Author: Uxper
Author URI: http://uxper.co/
Version: 1.0.1
Template: golo
Text Domain: golo
Tags: editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready
*/
@import url("../$parent_theme/style.css");
CSS;
file_put_contents("$child_dir/style.css", $style);
file_put_contents("$child_dir/screenshot.png", file_get_contents(get_template_directory() . '/screenshot.png'));
file_put_contents("$child_dir/README.txt", "This is a child theme of $parent_theme.");
file_put_contents("$child_dir/functions.php", "<?php\n// Child theme functions\n");
}
switch_theme($child_slug);
}
public function ocdi_plugin_intro_text( $default_text ) {
ob_start();
?>
<div class="golo-box golo-box--orange golo-box--import-notes" style="margin-bottom: 20px;">
<div class="golo-box__header">
<span class="golo-box__icon"><i class="fad fa-comment-exclamation"></i></span>
<h3>Important Notes</h3>
</div>
<div class="golo-box__body">
<ol>
<li>
No existing posts, pages, categories, images, widgets or any other data will be deleted or modifed, but we recommend installing demo data on a clean WordPress website to prevent conflicts with your current content.<br>To reset your website before importing, use <a href="https://golo.go/wp-admin/plugin-install.php?tab=plugin-information&plugin=wordpress-reset&TB_iframe=true&width=800&height=550" class="thickbox" title="Install WordPress Reset">WordPress Reset</a> plugin. </li>
<li><strong>All required plugins</strong> should be installed.</li>
<li>
After importing demo data, you should use <a href="https://golo.go/wp-admin/plugin-install.php?tab=plugin-information&plugin=regenerate-thumbnails&TB_iframe=true&width=800&height=550" class="thickbox" title="Install Regenerate Thumbnails">Regenerate Thumbnails</a> plugin. </li>
<li>
Posts, pages, images, widgets, menus and more data will get imported.<br>Please click on the "Import" button only once and wait until the process is completed, it may take a while. </li>
</ol>
</div>
</div>
<?php
$default_text = ob_get_clean();
return $default_text;
}
}
new Golo_Framework_Importer();