<div class="theme-offer">
	<?php 
        // Check if the demo import has been completed
        $podcaster_radio_demo_import_completed = get_option('podcaster_radio_demo_import_completed', false);

        // If the demo import is completed, display the "View Site" button
        if ($podcaster_radio_demo_import_completed) {
        echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'podcaster-radio') . '</p>';
        echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'podcaster-radio') . '</a></span>';
        echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'podcaster-radio' ) .'</a></span>';
        echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-podcaster-radio/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'podcaster-radio' ) .'</a></span>';
    }

		//POST and update the customizer and other related data
        if (isset($_POST['submit'])) {
            // Check if ibtana visual editor is installed and activated
            if (!is_plugin_active('ibtana-visual-editor/plugin.php')) {
              // Install the plugin if it doesn't exist
              $podcaster_radio_plugin_slug = 'ibtana-visual-editor';
              $podcaster_radio_plugin_file = 'ibtana-visual-editor/plugin.php';

              // Check if plugin is installed
              $podcaster_radio_installed_plugins = get_plugins();
              if (!isset($podcaster_radio_installed_plugins[$podcaster_radio_plugin_file])) {
                  include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
                  include_once(ABSPATH . 'wp-admin/includes/file.php');
                  include_once(ABSPATH . 'wp-admin/includes/misc.php');
                  include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');

                  // Install the plugin
                  $podcaster_radio_upgrader = new Plugin_Upgrader();
                  $podcaster_radio_upgrader->install('https://downloads.wordpress.org/plugin/ibtana-visual-editor.latest-stable.zip');
              }
              // Activate the plugin
              activate_plugin($podcaster_radio_plugin_file);
            } 

            if (!is_plugin_active('audioigniter/audioigniter.php')) {
                // Plugin details
                $podcaster_radio_audioigniter_plugin_slug = 'audioigniter';
                $podcaster_radio_audioigniter_plugin_file = 'audioigniter/audioigniter.php';
            
                // Check if plugin is installed
                $podcaster_radio_installed_plugins = get_plugins();
                if (!isset($podcaster_radio_installed_plugins[$podcaster_radio_audioigniter_plugin_file])) {
                    // Include necessary WordPress files for plugin installation
                    include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
                    include_once(ABSPATH . 'wp-admin/includes/file.php');
                    include_once(ABSPATH . 'wp-admin/includes/misc.php');
                    include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
            
                    // Install the plugin
                    $podcaster_radio_plugin_upgrader = new Plugin_Upgrader();
                    $podcaster_radio_plugin_upgrader->install('https://downloads.wordpress.org/plugin/audioigniter.latest-stable.zip');
                }
            
                // Activate the plugin
                activate_plugin($podcaster_radio_audioigniter_plugin_file);
            } 

            // ------- Create Nav Menu --------
            $podcaster_radio_menuname = 'Main Menus';
            $podcaster_radio_bpmenulocation = 'primary';
            $podcaster_radio_menu_exists = wp_get_nav_menu_object($podcaster_radio_menuname);

            if (!$podcaster_radio_menu_exists) {
                $podcaster_radio_menu_id = wp_create_nav_menu($podcaster_radio_menuname);

                // Create Home Page
                $podcaster_radio_home_title = 'Home';
                $podcaster_radio_home = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_home_title,
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'home'
                );
                $podcaster_radio_home_id = wp_insert_post($podcaster_radio_home);
                // Assign Home Page Template
                add_post_meta($podcaster_radio_home_id, '_wp_page_template', 'page-template/custom-home-page.php');
                // Update options to set Home Page as the front page
                update_option('page_on_front', $podcaster_radio_home_id);
                update_option('show_on_front', 'page');
                // Add Home Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'podcaster-radio'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_home_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Pages Page with Dummy Content
                $podcaster_radio_pages_title = 'Pages';
                $podcaster_radio_pages_content = '
                <p>Explore all the pages we have on our website. Find information about our services, company, and more.</p>

                 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> 

                  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.';
                $podcaster_radio_pages = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_pages_title,
                    'post_content' => $podcaster_radio_pages_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'pages'
                );
                $podcaster_radio_pages_id = wp_insert_post($podcaster_radio_pages);
                // Add Pages Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('Pages', 'podcaster-radio'),
                    'menu-item-classes' => 'pages',
                    'menu-item-url' => home_url('/pages/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_pages_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Trending Page with Dummy Content
                $podcaster_radio_about_title = 'Trending';
                $podcaster_radio_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.';
                $podcaster_radio_about = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_about_title,
                    'post_content' => $podcaster_radio_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'trending'
                );
                $podcaster_radio_about_id = wp_insert_post($podcaster_radio_about);
                // Add Trending Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('Trending', 'podcaster-radio'),
                    'menu-item-classes' => 'trending',
                    'menu-item-url' => home_url('/trending/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create Upcoming Page with Dummy Content
                $podcaster_radio_about_title = 'Upcoming';
                $podcaster_radio_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.';
                $podcaster_radio_about = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_about_title,
                    'post_content' => $podcaster_radio_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'upcoming'
                );
                $podcaster_radio_about_id = wp_insert_post($podcaster_radio_about);
                // Add Upcoming Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('Upcoming', 'podcaster-radio'),
                    'menu-item-classes' => 'upcoming',
                    'menu-item-url' => home_url('/upcoming/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

                // Create News Page with Dummy Content
                $podcaster_radio_about_title = 'News';
                $podcaster_radio_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.';
                $podcaster_radio_about = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_about_title,
                    'post_content' => $podcaster_radio_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'news'
                );
                $podcaster_radio_about_id = wp_insert_post($podcaster_radio_about);
                // Add News Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('News', 'podcaster-radio'),
                    'menu-item-classes' => 'news',
                    'menu-item-url' => home_url('/news/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));
                
                // Create Contact Page with Dummy Content
                $podcaster_radio_about_title = 'Contact';
                $podcaster_radio_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.';
                $podcaster_radio_about = array(
                    'post_type' => 'page',
                    'post_title' => $podcaster_radio_about_title,
                    'post_content' => $podcaster_radio_about_content,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_slug' => 'contact'
                );
                $podcaster_radio_about_id = wp_insert_post($podcaster_radio_about);
                // Add Contact Page to Menu
                wp_update_nav_menu_item($podcaster_radio_menu_id, 0, array(
                    'menu-item-title' => __('Contact', 'podcaster-radio'),
                    'menu-item-classes' => 'contact',
                    'menu-item-url' => home_url('/contact/'),
                    'menu-item-status' => 'publish',
                    'menu-item-object-id' => $podcaster_radio_about_id,
                    'menu-item-object' => 'page',
                    'menu-item-type' => 'post_type'
                ));

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

         
            // Set the demo import completion flag
    		update_option('podcaster_radio_demo_import_completed', true);
    		// Display success message and "View Site" button
    		echo '<p class="notice-text">' . esc_html__('Your demo import has been completed successfully.', 'podcaster-radio') . '</p>';
    		echo '<span><a href="' . esc_url(home_url()) . '" class="button button-primary site-btn" target="_blank">' . esc_html__('View Site', 'podcaster-radio') . '</a></span>';
            echo '<span><a href="'. esc_url(admin_url('customize.php') ) .'" class="button button-primary demo-btn" target=_blank>'. esc_html__( 'Customize Your Site', 'podcaster-radio' ) .'</a></span>';
            echo '<span><a href="'. esc_url( 'https://preview.vwthemesdemo.com/docs/free-podcaster-radio/' ) .'" class="button button-primary doc-btn" target=_blank>'. esc_html__( 'Free Theme Documentation', 'podcaster-radio' ) .'</a></span>';
            //end 


            // Top Bar //
            set_theme_mod( 'podcaster_radio_topbar_text', 'Welcome To Podcast!' );  
            set_theme_mod( 'podcaster_radio_topbar_support_link', '#' );
            set_theme_mod( 'podcaster_radio_topbar_wishlist_link', '#' );
            set_theme_mod( 'podcaster_radio_topbar_myaccount_link', '#' );

            // slider section start //      
            set_theme_mod( 'podcaster_radio_slider_button_text', 'EXPLORE ALL' );
            set_theme_mod( 'podcaster_radio_topbar_btn_link', '#' );
            set_theme_mod( 'podcaster_radio_slider_button_icon', 'fas fa-arrow-right' );

            for($podcaster_radio_i=1;$podcaster_radio_i<=3;$podcaster_radio_i++){
               $podcaster_radio_slider_title = 'Easy To Listen Any Time And Any Where';
               $podcaster_radio_slider_content = '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';
                  // Create post object
               $my_post = array(
               'post_title'    => wp_strip_all_tags( $podcaster_radio_slider_title ),
               'post_content'  => $podcaster_radio_slider_content,
               'post_status'   => 'publish',
               'post_type'     => 'page',
               );

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

               if ($podcaster_radio_post_id) {
                 // Set the theme mod for the slider page
                 set_theme_mod('podcaster_radio_slider_page' . $podcaster_radio_i, $podcaster_radio_post_id);

                  $podcaster_radio_image_url = get_template_directory_uri().'/assets/images/slider'.$podcaster_radio_i.'.png';

                $podcaster_radio_image_id = media_sideload_image($podcaster_radio_image_url, $podcaster_radio_post_id, null, 'id');

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


            // Track Player Section
            for ($podcaster_radio_i = 1; $podcaster_radio_i <= 2; $podcaster_radio_i++) {
                $podcaster_radio_featured_album = array();
                $podcaster_radio_content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 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 1960s 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.";

                // Create post object
                $podcaster_radio_my_post = array(
                    'post_title'   => 'Featured-album-' . $podcaster_radio_i,
                    'post_content' => $podcaster_radio_content,
                    'post_status'  => 'publish',
                    'post_type'    => 'ai_playlist',
                );

                // Insert the post into the database
                $podcaster_radio_bwt_post_id = wp_insert_post($podcaster_radio_my_post);

                if (is_wp_error($podcaster_radio_bwt_post_id)) {
                    add_action('admin_notices', function () {
                        echo '<div class="notice notice-error is-dismissible">
                            <p>Failed to create playlist post.</p>
                        </div>';
                    });
                    continue;
                }

                $podcaster_radio_image_url = get_template_directory_uri() . '/assets/images/track.png';
                $podcaster_radio_image_name = 'track_image_' . $podcaster_radio_i . '.png';
                $podcaster_radio_upload_dir = wp_upload_dir();

                // Get image data
                $podcaster_radio_image_data = @file_get_contents($podcaster_radio_image_url);
                if ($podcaster_radio_image_data === false) {
                    add_action('admin_notices', function () use ($podcaster_radio_image_url) {
                        echo '<div class="notice notice-error is-dismissible">
                            <p>Failed to fetch image: ' . esc_html($podcaster_radio_image_url) . '</p>
                        </div>';
                    });
                    continue;
                }

                $podcaster_radio_unique_file_name = wp_unique_filename($podcaster_radio_upload_dir['path'], $podcaster_radio_image_name);
                $podcaster_radio_filename = basename($podcaster_radio_unique_file_name);

                // Define file location
                $podcaster_radio_file = wp_mkdir_p($podcaster_radio_upload_dir['path']) ? $podcaster_radio_upload_dir['path'] . '/' . $podcaster_radio_filename : $podcaster_radio_upload_dir['basedir'] . '/' . $podcaster_radio_filename;

                $podcaster_radio_filename = basename( $podcaster_radio_file );

                        $podcaster_radio_upload = wp_upload_bits(
                            $podcaster_radio_filename,
                            null,
                            $podcaster_radio_image_data
                        );

                        if ( ! $podcaster_radio_upload['error'] ) {
                            $podcaster_radio_file = $podcaster_radio_upload['file'];
                        }

                // Check image file type
                $podcaster_radio_wp_filetype = wp_check_filetype($podcaster_radio_filename, null);
                $podcaster_radio_attachment = array(
                    'post_mime_type' => $podcaster_radio_wp_filetype['type'],
                    'post_title'     => sanitize_file_name($podcaster_radio_filename),
                    'post_content'   => '',
                    'post_status'    => 'inherit',
                );

                // Create the attachment
                $podcaster_radio_attach_id = wp_insert_attachment($podcaster_radio_attachment, $podcaster_radio_file, $podcaster_radio_bwt_post_id);
                require_once(ABSPATH . 'wp-admin/includes/image.php');
                $podcaster_radio_attach_data = wp_generate_attachment_metadata($podcaster_radio_attach_id, $podcaster_radio_file);
                wp_update_attachment_metadata($podcaster_radio_attach_id, $podcaster_radio_attach_data);

                $podcaster_radio_player_url = get_template_directory_uri() . '/assets/images/audio/sample.mp3';

                // Add tracks
                $podcaster_radio_featured_album_tracks = array();
                    $podcaster_radio_featured_album_tracks[] = array(
                        'cover_id'               => $podcaster_radio_attach_id,
                        'title'                  => 'Lorem Ipsum',
                        'artist'                 => 'Mike Hunt',
                        'track_url'              => $podcaster_radio_player_url,
                        'buy_link'               => '#',
                        'download_url'           => $podcaster_radio_player_url,
                        'download_uses_track_url' => '0',
                    );


                // Save track data as metadata
                update_post_meta($podcaster_radio_bwt_post_id, '_audioigniter_tracks', $podcaster_radio_featured_album_tracks);

               
            }   

            // Create the 'Products' page if it doesn't exist
            $podcaster_radio_page_query = new WP_Query(array(
                'post_type'      => 'page',
                'title'          => 'Page1',
                'post_status'    => 'publish',
                'posts_per_page' => 1
            ));

            if (!$podcaster_radio_page_query->have_posts()) {
                $podcaster_radio_page_title = 'Audio Track Page';
                $productpage = '[ai_playlist id="' . $podcaster_radio_bwt_post_id . '"]';

                // Append the WooCommerce products shortcode to the content
                $podcaster_radio_content = '';
                $podcaster_radio_content .= do_shortcode($productpage);

                // Create the new page
                $podcaster_radio_page = array(
                    'post_type'    => 'page',
                    'post_title'   => $podcaster_radio_page_title,
                    'post_content' => $podcaster_radio_content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                    'post_slug'    => 'products'
                );

                // Insert the page and get its ID
                $podcaster_radio_page_id = wp_insert_post($podcaster_radio_page);

                // Store the page ID in theme mod
                if (!is_wp_error($podcaster_radio_page_id)) {
                    set_theme_mod('podcaster_radio_track_player_page', $podcaster_radio_page_id);
                }
            }

            // Podcast Series section
            set_theme_mod('podcaster_radio_series_podcast_small_title', 'LISTEN TO COMPLETE SERIES' );
            set_theme_mod('podcaster_radio_series_podcast_heading', 'PODCAST SERIES' );
            set_theme_mod('podcaster_radio_podcast_button_icon', 'fas fa-play' );
            set_theme_mod('podcaster_radio_series_podcast_category', 'service-cat1' );

            // Define post category names and post titles
            $podcaster_radio_category_names = array('service-cat1', 'service-cat2');
            $podcaster_radio_title_array = array(
                array("Cook With Dixie", "Business Today", "Career Choices", "Business Today"),
                array("Cook With Dixie", "Business Today", "Career Choices", "Business Today")
            );

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

                for ($podcaster_radio_i = 0; $podcaster_radio_i < 3; $podcaster_radio_i++) {
                    // Create post content
                    $podcaster_radio_title = $podcaster_radio_title_array[$podcaster_radio_index][$podcaster_radio_i];
                    $podcaster_radio_content = '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.';

                    // Create post post object
                    $podcaster_radio_my_post = array(
                        'post_title'    => wp_strip_all_tags($podcaster_radio_title),
                        'post_content'  => $podcaster_radio_content,
                        'post_status'   => 'publish',
                        'post_type'     => 'post', // Post type set to 'post'
                    );

                    // Insert the post into the database
                    $podcaster_radio_post_id = wp_insert_post($podcaster_radio_my_post);

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

                    // Assign the category to the post
                    wp_set_post_categories($podcaster_radio_post_id, array((int)$podcaster_radio_term['term_id']));

                    // Handle the featured image using media_sideload_image
                    $podcaster_radio_image_url = get_template_directory_uri() . '/assets/images/services' . ($podcaster_radio_i + 1) . '.png';
                    $podcaster_radio_image_id = media_sideload_image($podcaster_radio_image_url, $podcaster_radio_post_id, null, 'id');

                    if (is_wp_error($podcaster_radio_image_id)) {
                        error_log('Error downloading image: ' . $podcaster_radio_image_id->get_error_message());
                        continue; // Skip to the next post if image download fails
                    }
                    // Assign featured image to post
                    set_post_thumbnail($podcaster_radio_post_id, $podcaster_radio_image_id);
                }
            } 
            
        }
        
    ?>

    <form action="<?php echo esc_url(home_url()); ?>/wp-admin/themes.php?page=podcaster_radio_guide" method="POST" onsubmit="return validate(this);">
        <?php if (!get_option('podcaster_radio_demo_import_completed')) : ?>
            <form method="post">   
            <p class="run-import-text"><?php esc_html_e('Click On The Below Run Importer Button To Import Demo Content Of podcaster radio', 'podcaster-radio'); ?></p>
                <p><?php esc_html_e('Please back up your website if it’s already live with data. This importer will overwrite your existing settings with the new customizer values for podcaster radio', 'podcaster-radio'); ?></p>
                <input class="run-import" type="submit" name="submit" value="<?php esc_attr_e('Run Importer', 'podcaster-radio'); ?>" class="button button-primary button-large">
                 </form>  
        <?php endif; ?>
        <div id="spinner" style="display:none;">         
            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/spinner.png" alt="" />
        </div>
    </form>
    <script type="text/javascript">
        function validate(form) {
            if (confirm("Do you really want to import the theme demo content?")) {
                // Show the spinner
                document.getElementById('spinner').style.display = 'block';
                // Allow the form to be submitted
                return true;
            } 
            else {
                return false;
            }
        }
    </script>
</div>

