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

if (!$crowdfunding_nonprofit_menu_exists) {
    $crowdfunding_nonprofit_menu_id = wp_create_nav_menu($crowdfunding_nonprofit_menuname);

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

    // Assign Home Page Template
    add_post_meta($crowdfunding_nonprofit_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', $crowdfunding_nonprofit_home_id);
    update_option('show_on_front', 'page');

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

    // Create About Us Page with Dummy Content
    $crowdfunding_nonprofit_about_title = 'About Us';
    $crowdfunding_nonprofit_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.';
    $crowdfunding_nonprofit_about = array(
        'post_type' => 'page',
        'post_title' => $crowdfunding_nonprofit_about_title,
        'post_content' => $crowdfunding_nonprofit_about_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'about-us'
    );
    $crowdfunding_nonprofit_about_id = wp_insert_post($crowdfunding_nonprofit_about);

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

    // Create Services Page with Dummy Content
    $crowdfunding_nonprofit_services_title = 'Services';
    $crowdfunding_nonprofit_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.';
    $crowdfunding_nonprofit_services = array(
        'post_type' => 'page',
        'post_title' => $crowdfunding_nonprofit_services_title,
        'post_content' => $crowdfunding_nonprofit_services_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'services'
    );
    $crowdfunding_nonprofit_services_id = wp_insert_post($crowdfunding_nonprofit_services);

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

    // Create Pages Page with Dummy Content
    $crowdfunding_nonprofit_pages_title = 'Pages';
    $crowdfunding_nonprofit_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>';
    $crowdfunding_nonprofit_pages = array(
        'post_type' => 'page',
        'post_title' => $crowdfunding_nonprofit_pages_title,
        'post_content' => $crowdfunding_nonprofit_pages_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'pages'
    );
    $crowdfunding_nonprofit_pages_id = wp_insert_post($crowdfunding_nonprofit_pages);

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

    // Create Contact Page with Dummy Content
    $crowdfunding_nonprofit_contact_title = 'Contact';
    $crowdfunding_nonprofit_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.';
    $crowdfunding_nonprofit_contact = array(
        'post_type' => 'page',
        'post_title' => $crowdfunding_nonprofit_contact_title,
        'post_content' => $crowdfunding_nonprofit_contact_content,
        'post_status' => 'publish',
        'post_author' => 1,
        'post_slug' => 'contact'
    );
    $crowdfunding_nonprofit_contact_id = wp_insert_post($crowdfunding_nonprofit_contact);

    // Add Contact Page to Menu
    wp_update_nav_menu_item($crowdfunding_nonprofit_menu_id, 0, array(
        'menu-item-title' => __('Contact', 'crowdfunding-nonprofit'),
        'menu-item-classes' => 'contact',
        'menu-item-url' => home_url('/contact/'),
        'menu-item-status' => 'publish',
        'menu-item-object-id' => $crowdfunding_nonprofit_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($crowdfunding_nonprofit_bpmenulocation)) {
        $locations = get_theme_mod('nav_menu_locations'); // Use 'nav_menu_locations' to get locations array
        if (empty($locations)) {
            $locations = array();
        }
        $locations[$crowdfunding_nonprofit_bpmenulocation] = $crowdfunding_nonprofit_menu_id;
        set_theme_mod('nav_menu_locations', $locations);
    }
}

        //---Header--//
        set_theme_mod('crowdfunding_nonprofit_facebook_url', '#');
        set_theme_mod('crowdfunding_nonprofit_twitter_url', '#');
        set_theme_mod('crowdfunding_nonprofit_instagram_url', '#');
        set_theme_mod('crowdfunding_nonprofit_youtube_url', '#');
        set_theme_mod('crowdfunding_nonprofit_pint_url', '#');

         // Slider Section
        set_theme_mod('crowdfunding_nonprofit_slider_arrows', true);
        set_theme_mod('crowdfunding_nonprofit_slider_short_heading', 'Empower. Inspire. Change.');
        set_theme_mod('crowdfunding_nonprofit_show_slider_title', 'Working together to create a brighter, better future.');
        set_theme_mod('crowdfunding_nonprofit_show_slider_content', 'Partner with us to bring positive change, support communities in need, and build a hopeful, empowered future for all.');
        set_theme_mod('crowdfunding_nonprofit_product_btn_text1', 'Explore more');
        set_theme_mod('crowdfunding_nonprofit_product_btn_link1', '#');
        set_theme_mod('crowdfunding_nonprofit_banner_main_img', get_template_directory_uri().'/assets/images/post-img1.png');
        set_theme_mod('crowdfunding_nonprofit_donation_received', '70000.00');
        set_theme_mod('crowdfunding_nonprofit_donation_goal', '90000.00');
        set_theme_mod('crowdfunding_nonprofit_donate_button_text', 'Donate Now');
        set_theme_mod('crowdfunding_nonprofit_donate_button_url', '#');
        set_theme_mod('crowdfunding_nonprofit_main_team1', 'Passionate team creating real change.');
        set_theme_mod('crowdfunding_nonprofit_short_img_banner1', get_template_directory_uri().'/assets/images/team1.png');
        set_theme_mod('crowdfunding_nonprofit_main_team2', 'Passionate team creating real change.');
        set_theme_mod('crowdfunding_nonprofit_short_img_banner2', get_template_directory_uri().'/assets/images/team2.png');
        set_theme_mod('crowdfunding_nonprofit_donate_btn_text1', 'Donate');
        set_theme_mod('crowdfunding_nonprofit_donate_btn_link1', '#');
        set_theme_mod('crowdfunding_nonprofit_story_reel_url', '#');
        set_theme_mod('crowdfunding_nonprofit_show_dedicated_title', 'Dedicated team');
        set_theme_mod('crowdfunding_nonprofit_show_dedicated_detail', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis dignissim neque. Nullam ultrices massa ut lectus laoreet malesuada. Pellentesque gravida at urna bibendum semper.');
        set_theme_mod('crowdfunding_nonprofit_customer_review', '80k+');

        set_theme_mod('crowdfunding_nonprofit_about_catData', 'postcategory2');

        // Define post category names and post titles
        $crowdfunding_nonprofit_category_names = array('postcategory2');
        $crowdfunding_nonprofit_title_array = array(
            array(
                "Dedicated Team Member 1",
                "Dedicated Team Member 2",
                "Dedicated Team Member 3",
                "Dedicated Team Member 4",
            )
        );

        $crowdfunding_nonprofit_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis dignissim neque. Nullam ultrices massa ut lectus laoreet malesuada. Pellentesque gravida at urna bibendum semper. Fusce sollicitudin tellus nisl, sit amet lobortis augue tincidunt vitae.';

        foreach ($crowdfunding_nonprofit_category_names as $crowdfunding_nonprofit_index => $crowdfunding_nonprofit_category_name) {
            // Create or retrieve the post category term ID
            $crowdfunding_nonprofit_term = term_exists($crowdfunding_nonprofit_category_name, 'category');
            if ($crowdfunding_nonprofit_term === 0 || $crowdfunding_nonprofit_term === null) {
                // If the term does not exist, create it
                $crowdfunding_nonprofit_term = wp_insert_term($crowdfunding_nonprofit_category_name, 'category');
            }
            if (is_wp_error($crowdfunding_nonprofit_term)) {
                error_log('Error creating category: ' . $crowdfunding_nonprofit_term->get_error_message());
                continue; // Skip to the next iteration if category creation fails
            }

            // Ensure we get the term ID
            $crowdfunding_nonprofit_term_id = is_array($crowdfunding_nonprofit_term) ? $crowdfunding_nonprofit_term['term_id'] : $crowdfunding_nonprofit_term;

            // Get titles for this category
            $crowdfunding_nonprofit_titles = $crowdfunding_nonprofit_title_array[$crowdfunding_nonprofit_index];

            for ($crowdfunding_nonprofit_i = 0; $crowdfunding_nonprofit_i < count($crowdfunding_nonprofit_titles); $crowdfunding_nonprofit_i++) {
                // Create post content
                $crowdfunding_nonprofit_title = $crowdfunding_nonprofit_titles[$crowdfunding_nonprofit_i];

                // Create post post object
                $crowdfunding_nonprofit_my_post = array(
                    'post_title'    => wp_strip_all_tags($crowdfunding_nonprofit_title),
                    'post_content'  => $crowdfunding_nonprofit_content,
                    'post_status'   => 'publish',
                    'post_type'     => 'post', // Post type set to 'post'
                );

                // Insert the post into the database
                $crowdfunding_nonprofit_post_id = wp_insert_post($crowdfunding_nonprofit_my_post);

                if (is_wp_error($crowdfunding_nonprofit_post_id)) {
                    error_log('Error creating post: ' . $crowdfunding_nonprofit_post_id->get_error_message());
                    continue; // Skip to the next post if creation fails
                }

                // Assign the category to the post
                wp_set_post_categories($crowdfunding_nonprofit_post_id, array((int)$crowdfunding_nonprofit_term_id));

                // Handle the featured image using media_sideload_image
                $crowdfunding_nonprofit_image_url = get_stylesheet_directory_uri() . '/assets/images/dedicate-team' . ($crowdfunding_nonprofit_i + 1) . '.png';
                $crowdfunding_nonprofit_image_id = media_sideload_image($crowdfunding_nonprofit_image_url, $crowdfunding_nonprofit_post_id, null, 'id');

                if (is_wp_error($crowdfunding_nonprofit_image_id)) {
                    error_log('Error downloading image: ' . $crowdfunding_nonprofit_image_id->get_error_message());
                    continue; // Skip to the next post if image download fails
                }

                // Assign featured image to post
                set_post_thumbnail($crowdfunding_nonprofit_post_id, $crowdfunding_nonprofit_image_id);
            }
        }

        // Our Services Section //

        set_theme_mod('crowdfunding_nonprofit_service_sub_heading', 'About Us');
        set_theme_mod('crowdfunding_nonprofit_featured_section_title', 'Hope. Impact. Change');
        set_theme_mod('crowdfunding_nonprofit_serv_content', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis dignissim neque. Nullam ultrices massa ut lectus laoreet malesuada.');

        set_theme_mod('crowdfunding_nonprofit_add_record_for_post1', '5,200+');
        set_theme_mod('crowdfunding_nonprofit_add_record_for_post2', '120+');
        set_theme_mod('crowdfunding_nonprofit_add_record_for_post3', '75+');
        set_theme_mod('crowdfunding_nonprofit_add_record_for_post4', '98%');

        set_theme_mod('crowdfunding_nonprofit_offer_section_category', 'postcategory1');

        // Define post category names and post titles
        $crowdfunding_nonprofit_category_names = array('postcategory1');
        $crowdfunding_nonprofit_title_array = array(
            array(
                "Lives Touched",
                "Ongoing Projects",
                "Local Partnership",
                "Donor Retention",
            )
        );

        $crowdfunding_nonprofit_content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis dignissim neque. Nullam ultrices massa ut lectus laoreet malesuada. Pellentesque gravida at urna bibendum semper. Fusce sollicitudin tellus nisl, sit amet lobortis augue tincidunt vitae.';

        foreach ($crowdfunding_nonprofit_category_names as $crowdfunding_nonprofit_index => $crowdfunding_nonprofit_category_name) {
            // Create or retrieve the post category term ID
            $crowdfunding_nonprofit_term = term_exists($crowdfunding_nonprofit_category_name, 'category');
            if ($crowdfunding_nonprofit_term === 0 || $crowdfunding_nonprofit_term === null) {
                // If the term does not exist, create it
                $crowdfunding_nonprofit_term = wp_insert_term($crowdfunding_nonprofit_category_name, 'category');
            }
            if (is_wp_error($crowdfunding_nonprofit_term)) {
                error_log('Error creating category: ' . $crowdfunding_nonprofit_term->get_error_message());
                continue; // Skip to the next iteration if category creation fails
            }

            // Ensure we get the term ID
            $crowdfunding_nonprofit_term_id = is_array($crowdfunding_nonprofit_term) ? $crowdfunding_nonprofit_term['term_id'] : $crowdfunding_nonprofit_term;

            // Get titles for this category
            $crowdfunding_nonprofit_titles = $crowdfunding_nonprofit_title_array[$crowdfunding_nonprofit_index];

            for ($crowdfunding_nonprofit_i = 0; $crowdfunding_nonprofit_i < count($crowdfunding_nonprofit_titles); $crowdfunding_nonprofit_i++) {
                // Create post content
                $crowdfunding_nonprofit_title = $crowdfunding_nonprofit_titles[$crowdfunding_nonprofit_i];

                // Create post post object
                $crowdfunding_nonprofit_my_post = array(
                    'post_title'    => wp_strip_all_tags($crowdfunding_nonprofit_title),
                    'post_content'  => $crowdfunding_nonprofit_content,
                    'post_status'   => 'publish',
                    'post_type'     => 'post', // Post type set to 'post'
                );

                // Insert the post into the database
                $crowdfunding_nonprofit_post_id = wp_insert_post($crowdfunding_nonprofit_my_post);

                if (is_wp_error($crowdfunding_nonprofit_post_id)) {
                    error_log('Error creating post: ' . $crowdfunding_nonprofit_post_id->get_error_message());
                    continue; // Skip to the next post if creation fails
                }

                // Assign the category to the post
                wp_set_post_categories($crowdfunding_nonprofit_post_id, array((int)$crowdfunding_nonprofit_term_id));

                // Handle the featured image using media_sideload_image
                $crowdfunding_nonprofit_image_url = get_stylesheet_directory_uri() . '/assets/images/post-img' . ($crowdfunding_nonprofit_i + 1) . '.png';
                $crowdfunding_nonprofit_image_id = media_sideload_image($crowdfunding_nonprofit_image_url, $crowdfunding_nonprofit_post_id, null, 'id');

                if (is_wp_error($crowdfunding_nonprofit_image_id)) {
                    error_log('Error downloading image: ' . $crowdfunding_nonprofit_image_id->get_error_message());
                    continue; // Skip to the next post if image download fails
                }

                // Assign featured image to post
                set_post_thumbnail($crowdfunding_nonprofit_post_id, $crowdfunding_nonprofit_image_id);
            }
        }
        

    }
?>