<?php 
if (isset($_GET['import-demo']) && $_GET['import-demo'] == true) {
    
    // ------- Create Nav Menu --------
$holiday_vacation_menuname = 'Main Menus';
$holiday_vacation_bpmenulocation = 'primary-menu';
$holiday_vacation_menu_exists = wp_get_nav_menu_object($holiday_vacation_menuname);

if (!$holiday_vacation_menu_exists) {
    $holiday_vacation_menu_id = wp_create_nav_menu($holiday_vacation_menuname);

    // Create Home Page
    $holiday_vacation_home_title = 'Home';
    $holiday_vacation_home = array(
        'post_type' => 'page',
        'post_title' => $holiday_vacation_home_title,
        'post_content' => '',
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'home'
    );
    $holiday_vacation_home_id = wp_insert_post($holiday_vacation_home);

    // Assign Home Page Template
    add_post_meta($holiday_vacation_home_id, '_wp_page_template', 'page-template/front-page.php');

    // Update options to set Home Page as the front page
    update_option('page_on_front', $holiday_vacation_home_id);
    update_option('show_on_front', 'page');

    // Add Home Page to Menu
    wp_update_nav_menu_item($holiday_vacation_menu_id, 0, array(
        'menu-item-title' => __('Home', 'holiday-vacation'),
        'menu-item-classes' => 'home',
        'menu-item-url' => home_url('/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $holiday_vacation_home_id,
        'menu-item-object' => 'page',
        'menu-item-type' => 'post_type'
    ));

    // Create About Us Page with Dummy Content
    $holiday_vacation_about_title = 'About Us';
    $holiday_vacation_about_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam...<br>

             Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br> 

                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text.<br> 

                All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
    $holiday_vacation_about = array(
        'post_type' => 'page',
        'post_title' => $holiday_vacation_about_title,
        'post_content' => $holiday_vacation_about_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'about-us'
    );
    $holiday_vacation_about_id = wp_insert_post($holiday_vacation_about);

    // Add About Us Page to Menu
    wp_update_nav_menu_item($holiday_vacation_menu_id, 0, array(
        'menu-item-title' => __('About Us', 'holiday-vacation'),
        'menu-item-classes' => 'about-us',
        'menu-item-url' => home_url('/about-us/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $holiday_vacation_about_id,
        'menu-item-object' => 'page',
        'menu-item-type' => 'post_type'
    ));

    // Create Services Page with Dummy Content
    $holiday_vacation_services_title = 'Services';
    $holiday_vacation_services_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam...<br>

             Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br> 

                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text.<br> 

                All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
    $holiday_vacation_services = array(
        'post_type' => 'page',
        'post_title' => $holiday_vacation_services_title,
        'post_content' => $holiday_vacation_services_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'services'
    );
    $holiday_vacation_services_id = wp_insert_post($holiday_vacation_services);

    // Add Services Page to Menu
    wp_update_nav_menu_item($holiday_vacation_menu_id, 0, array(
        'menu-item-title' => __('Services', 'holiday-vacation'),
        'menu-item-classes' => 'services',
        'menu-item-url' => home_url('/services/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $holiday_vacation_services_id,
        'menu-item-object' => 'page',
        'menu-item-type' => 'post_type'
    ));

    // Create Pages Page with Dummy Content
    $holiday_vacation_pages_title = 'Pages';
    $holiday_vacation_pages_content = '<h2>Our Pages</h2>
    <p>Explore all the pages we have on our website. Find information about our services, company, and more.</p>';
    $holiday_vacation_pages = array(
        'post_type' => 'page',
        'post_title' => $holiday_vacation_pages_title,
        'post_content' => $holiday_vacation_pages_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'pages'
    );
    $holiday_vacation_pages_id = wp_insert_post($holiday_vacation_pages);

    // Add Pages Page to Menu
    wp_update_nav_menu_item($holiday_vacation_menu_id, 0, array(
        'menu-item-title' => __('Pages', 'holiday-vacation'),
        'menu-item-classes' => 'pages',
        'menu-item-url' => home_url('/pages/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $holiday_vacation_pages_id,
        'menu-item-object' => 'page',
        'menu-item-type' => 'post_type'
    ));

    // Create Contact Page with Dummy Content
    $holiday_vacation_contact_title = 'Contact';
    $holiday_vacation_contact_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam...<br>

             Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960 with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br> 

                There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which dont look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isnt anything embarrassing hidden in the middle of text.<br> 

                All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.';
    $holiday_vacation_contact = array(
        'post_type' => 'page',
        'post_title' => $holiday_vacation_contact_title,
        'post_content' => $holiday_vacation_contact_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'contact'
    );
    $holiday_vacation_contact_id = wp_insert_post($holiday_vacation_contact);

    // Add Contact Page to Menu
    wp_update_nav_menu_item($holiday_vacation_menu_id, 0, array(
        'menu-item-title' => __('Contact', 'holiday-vacation'),
        'menu-item-classes' => 'contact',
        'menu-item-url' => home_url('/contact/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $holiday_vacation_contact_id,
        'menu-item-object' => 'page',
        'menu-item-type' => 'post_type'
    ));

    // Set the menu location if it's not already set
    if (!has_nav_menu($holiday_vacation_bpmenulocation)) {
        $locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
        if (empty($locations)) {
            $locations = array();
        }
        $locations[$holiday_vacation_bpmenulocation] = $holiday_vacation_menu_id;
        set_theme_mod('nav_menu_locations', $locations);
    }
}

        //---Header--//
        set_theme_mod('holiday_vacation_header_fb_new_tab', true);
        set_theme_mod('holiday_vacation_facebook_url', '#');
        set_theme_mod('holiday_vacation_facebook_icon', 'fab fa-facebook-f');

        set_theme_mod('holiday_vacation_header_twt_new_tab', true);
        set_theme_mod('holiday_vacation_twitter_url', '#');
        set_theme_mod('holiday_vacation_twitter_icon', 'fab fa-twitter');

        set_theme_mod('holiday_vacation_header_ins_new_tab', true);
        set_theme_mod('holiday_vacation_instagram_url', '#');
        set_theme_mod('holiday_vacation_instagram_icon', 'fab fa-instagram');

        set_theme_mod('holiday_vacation_header_ut_new_tab', true);
        set_theme_mod('holiday_vacation_youtube_url', '#');
        set_theme_mod('holiday_vacation_youtube_icon', 'fab fa-youtube');

        set_theme_mod('holiday_vacation_header_pint_new_tab', true);
        set_theme_mod('holiday_vacation_pint_url', '#');
        set_theme_mod('holiday_vacation_pinterest_icon', 'fab fa-pinterest');

        // Slider Section
        set_theme_mod('holiday_vacation_slider_arrows', true);

        set_theme_mod('holiday_vacation_slider_short_heading', 'Indulge your adventurous spirit');


        for ($i = 1; $i <= 4; $i++) {
            $holiday_vacation_title = 'Discover Your World';

            // Create post object
            $my_post = array(
                'post_title'    => wp_strip_all_tags($holiday_vacation_title),
                'post_status'   => 'publish',
                'post_type'     => 'page',
            );

            // Insert the post into the database
            $post_id = wp_insert_post($my_post);

            if ($post_id) {
                // Set the theme mod for the slider page
                set_theme_mod('holiday_vacation_slider_page' . $i, $post_id);

                $image_url = get_template_directory_uri() . '/assets/images/slider-img.png';
                $image_id = media_sideload_image($image_url, $post_id, null, 'id');

                if (!is_wp_error($image_id)) {
                    // Set the downloaded image as the post's featured image
                    set_post_thumbnail($post_id, $image_id);
                }
            }
        }

        // Set theme mods for services
        set_theme_mod('holiday_vacation_category_tab_heading', 'Explore Places');
        set_theme_mod('holiday_vacation_tab_icon1', 'fas fa-home');
        set_theme_mod('holiday_vacation_tab_icon2', 'fas fa-laptop-house');
        set_theme_mod('holiday_vacation_tab_icon3', 'fas fa-house-damage');
        set_theme_mod('holiday_vacation_tab_icon4', 'fas fa-house-user');
        set_theme_mod('holiday_vacation_tab_icon5', 'fas fa-water');
        set_theme_mod('holiday_vacation_tab_icon6', 'fas fa-shopping-bag');

        // Create one category: postcategory1
        $category_name = 'postcategory1';
        $category_id = wp_create_category($category_name);

        // Set tab titles and assign same category to all
        $tab_titles = array('Frames', 'Amazing Views', 'Tiny Homes', 'Luxe', 'Lake View Resorts', 'Tree Houses');

        for ($i = 1; $i <= 6; $i++) {
            set_theme_mod('holiday_vacation_entertainment_tab_title' . $i, $tab_titles[$i - 1]);
            set_theme_mod('holiday_vacation_entertainment_tab_category_one' . $i, $category_name);
        }

        // Create demo posts under 'postcategory1'
        $blog_titles = array(
            'Greece, Santorini',
            'The Green Forest',
            'Mount Fuji',
            'Switzerland'
        );

        for ($i = 1; $i <= count($blog_titles); $i++) {
            $title = $blog_titles[$i - 1];

            $my_post = array(
                'post_title'  => wp_strip_all_tags($title),
                'post_status' => 'publish',
                'post_type'   => 'post',
                'post_category' => array($category_id)
            );

            $post_id = wp_insert_post($my_post);

            // Add featured image
            $image_url = get_template_directory_uri() . '/assets/images/post-img' . $i . '.png';
            $image_name = 'blogs' . $i . '.png';

            $upload_dir = wp_upload_dir();
            $image_data = @file_get_contents($image_url);

            if ($image_data === false) {
                continue;
            }

            $unique_file_name = wp_unique_filename($upload_dir['path'], $image_name);
            $filename = basename($unique_file_name);
            $file = $upload_dir['path'] . '/' . $filename;

            if (!function_exists('WP_Filesystem')) {
                require_once(ABSPATH . 'wp-admin/includes/file.php');
            }

            WP_Filesystem();
            global $wp_filesystem;

            if (!$wp_filesystem->put_contents($file, $image_data, FS_CHMOD_FILE)) {
                continue;
            }

            $wp_filetype = wp_check_filetype($filename, null);

            $attachment = array(
                'post_mime_type' => $wp_filetype['type'],
                'post_title'     => sanitize_file_name($filename),
                'post_content'   => '',
                'post_status'    => 'inherit'
            );

            $attach_id = wp_insert_attachment($attachment, $file, $post_id);

            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $attach_data = wp_generate_attachment_metadata($attach_id, $file);
            wp_update_attachment_metadata($attach_id, $attach_data);
            set_post_thumbnail($post_id, $attach_id);
        }

    }
?>