<?php
if (isset($_GET['import-demo']) && $_GET['import-demo'] == true) {
    class ProfessionalVideoVloggerDemoImporter {

        public function professional_video_vlogger_customizer_primary_menu() {
            // Create Primary Menu
            $professional_video_vlogger_themename = 'Professional Video Vlogger'; // Define the theme name
            $professional_video_vlogger_menuname = $professional_video_vlogger_themename . 'Main Menus';
            $professional_video_vlogger_bpmenulocation = 'main-menu';
            $professional_video_vlogger_menu_exists = wp_get_nav_menu_object($professional_video_vlogger_menuname);

            if (!$professional_video_vlogger_menu_exists) {
                $professional_video_vlogger_menu_id = wp_create_nav_menu($professional_video_vlogger_menuname);

                wp_update_nav_menu_item($professional_video_vlogger_menu_id, 0, array(
                    'menu-item-title' => __('Home', 'professional-video-vlogger'),
                    'menu-item-classes' => 'home',
                    'menu-item-url' => home_url('/'),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_video_vlogger_menu_id, 0, array(
                    'menu-item-title' => __('Featured Video', 'professional-video-vlogger'),
                    'menu-item-classes' => 'featured-video',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Featured Video')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_video_vlogger_menu_id, 0, array(
                    'menu-item-title' => __('About Us', 'professional-video-vlogger'),
                    'menu-item-classes' => 'about-us',
                    'menu-item-url' => get_permalink(get_page_id_by_title('About Us')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_video_vlogger_menu_id, 0, array(
                    'menu-item-title' => __('Blog', 'professional-video-vlogger'),
                    'menu-item-classes' => 'blog',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Blog')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_video_vlogger_menu_id, 0, array(
                    'menu-item-title' => __('Contact Us', 'professional-video-vlogger'),
                    'menu-item-classes' => 'contact-us',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Contact Us')),
                    'menu-item-status' => 'publish',
                ));

                if (!has_nav_menu($professional_video_vlogger_bpmenulocation)) {
                    $locations = get_theme_mod('nav_menu_locations');
                    $locations[$professional_video_vlogger_bpmenulocation] = $professional_video_vlogger_menu_id;
                    set_theme_mod('nav_menu_locations', $locations);
                }
            }
        }

        public function setup_widgets() {

        $professional_video_vlogger_home_id='';
        $professional_video_vlogger_home_content = '';
        $professional_video_vlogger_home_title = 'Home';
        $professional_video_vlogger_home = array(
            'post_type' => 'page',
            'post_title' => $professional_video_vlogger_home_title,
            'post_content' => $professional_video_vlogger_home_content,
            'post_status' => 'publish',
            'post_author' => 1,
            'post_slug' => 'home'
        );
        $professional_video_vlogger_home_id = wp_insert_post($professional_video_vlogger_home);

        add_post_meta( $professional_video_vlogger_home_id, '_wp_page_template', 'frontpage.php' );

        update_option( 'page_on_front', $professional_video_vlogger_home_id );
        update_option( 'show_on_front', 'page' );

                        // Create a Posts Page
            $professional_video_vlogger_blog_title = 'Featured Video';
            $professional_video_vlogger_blog_check = get_page_id_by_title($professional_video_vlogger_blog_title);

            if ($professional_video_vlogger_blog_check == 1) {
                $professional_video_vlogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_video_vlogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'featured-video',
                    'post_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, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
                );
                $professional_video_vlogger_blog_id = wp_insert_post($professional_video_vlogger_blog);

                if (!is_wp_error($professional_video_vlogger_blog_id)) {
                    // update_option('page_for_posts', $professional_video_vlogger_blog_id);
                }
            }

                        // Create a Posts Page
            $professional_video_vlogger_blog_title = 'About Us';
            $professional_video_vlogger_blog_check = get_page_id_by_title($professional_video_vlogger_blog_title);

            if ($professional_video_vlogger_blog_check  == 1) {
                $professional_video_vlogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_video_vlogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'about-us',
                    'post_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, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
                );
                $professional_video_vlogger_blog_id = wp_insert_post($professional_video_vlogger_blog);

                if (!is_wp_error($professional_video_vlogger_blog_id)) {
                    // update_option('page_for_posts', $professional_video_vlogger_blog_id);
                }
            }

                         // Create a Posts Page
            $professional_video_vlogger_blog_title = 'Blog';
            $professional_video_vlogger_blog_check = get_page_id_by_title($professional_video_vlogger_blog_title);

            if ($professional_video_vlogger_blog_check  == 1) {
                $professional_video_vlogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_video_vlogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'blog',
                    'post_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, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
                );
                $professional_video_vlogger_blog_id = wp_insert_post($professional_video_vlogger_blog);

                if (!is_wp_error($professional_video_vlogger_blog_id)) {
                    // update_option('page_for_posts', $professional_video_vlogger_blog_id);
                }
            }

                                     // Create a Posts Page
            $professional_video_vlogger_blog_title = 'Contact Us';
            $professional_video_vlogger_blog_check = get_page_id_by_title($professional_video_vlogger_blog_title);

            if ($professional_video_vlogger_blog_check  == 1) {
                $professional_video_vlogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_video_vlogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'contact-us',
                    'post_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, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
                );
                $professional_video_vlogger_blog_id = wp_insert_post($professional_video_vlogger_blog);

                if (!is_wp_error($professional_video_vlogger_blog_id)) {
                    // update_option('page_for_posts', $professional_video_vlogger_blog_id);
                }
            }

		//---Header--//

        set_theme_mod('professional_video_vlogger_social_links_settings', array(
            array(
                "link_text" => "fab fa-instagram",
                "link_url" => "#"
            ),
            array(
                "link_text" => "fab fa-twitter",
                "link_url" => "#"
            ),
            array(
                "link_text" => "fab fa-youtube",
                "link_url" => "#"
            ),
            array(
                "link_text" => "fab fa-linkedin-in",
                "link_url" => "#"
            )
        ));

		//-----Slider-----//

		set_theme_mod( 'professional_video_vlogger_blog_box_enable', true);

		set_theme_mod( 'professional_video_vlogger_blog_slide_number', '3' );
		$professional_video_vlogger_latest_post_category = wp_create_category('Slider Post');
			set_theme_mod( 'professional_video_vlogger_blog_slide_category', 'Slider Post' ); 

		for($i=1; $i<=3; $i++) {

			$title=array('Now Every Day Is Holiday, How', 'Every day is a holiday now, but how', 'How Come Every Day Is a Holiday Now?');

			// Create post object
			$professional_video_vlogger_my_post = array(
				'post_title'    => wp_strip_all_tags( $title[$i-1] ),
				'post_status'   => 'publish',
				'post_type'     => 'post',
				'post_category' => array($professional_video_vlogger_latest_post_category) 
			);

			// Insert the post into the database
			$professional_video_vlogger_post_id = wp_insert_post( $professional_video_vlogger_my_post );

			$professional_video_vlogger_image_url = get_template_directory_uri().'/assets/images/slider'.$i.'.png';

			$professional_video_vlogger_image_name= 'slider'.$i.'.png';
			$professional_video_vlogger_upload_dir = wp_upload_dir(); 
			// Set upload folder
			$professional_video_vlogger_image_data = file_get_contents($professional_video_vlogger_image_url); 
			 
			// Get image data
			$professional_video_vlogger_unique_file_name = wp_unique_filename( $professional_video_vlogger_upload_dir['path'], $professional_video_vlogger_image_name ); 
			// Generate unique name
			$filename= basename( $professional_video_vlogger_unique_file_name ); 
			// Create image file name
			// Check folder permission and define file location
			if( wp_mkdir_p( $professional_video_vlogger_upload_dir['path'] ) ) {
				$file = $professional_video_vlogger_upload_dir['path'] . '/' . $filename;
			} else {
				$file = $professional_video_vlogger_upload_dir['basedir'] . '/' . $filename;
			}

            // Create the image  file on the server
            if ( ! function_exists( 'WP_Filesystem' ) ) {
                require_once( ABSPATH . 'wp-admin/includes/file.php' );
            }
            
            WP_Filesystem();
            global $wp_filesystem;
            
            if ( ! $wp_filesystem->put_contents( $file, $professional_video_vlogger_image_data, FS_CHMOD_FILE ) ) {
                wp_die( 'Error saving file!' );
            }
            
			$professional_video_vlogger_wp_filetype = wp_check_filetype( $filename, null );
			$professional_video_vlogger_attachment = array(
				'post_mime_type' => $professional_video_vlogger_wp_filetype['type'],
				'post_title'     => sanitize_file_name( $filename ),
				'post_content'   => '',
				'post_type'     => 'post',
				'post_status'    => 'inherit'
			);
			$professional_video_vlogger_attach_id = wp_insert_attachment( $professional_video_vlogger_attachment, $file, $professional_video_vlogger_post_id );
			require_once(ABSPATH . 'wp-admin/includes/image.php');
			$professional_video_vlogger_attach_data = wp_generate_attachment_metadata( $professional_video_vlogger_attach_id, $file );
				wp_update_attachment_metadata( $professional_video_vlogger_attach_id, $professional_video_vlogger_attach_data );
				set_post_thumbnail( $professional_video_vlogger_post_id, $professional_video_vlogger_attach_id );
		}

        //--------------Blog Section-----------//

        set_theme_mod( 'professional_video_vlogger_gallery_section_enable', true);

        set_theme_mod( 'professional_video_vlogger_gallery_heading_text', 'TRENDING VIDEOS' );

        set_theme_mod( 'professional_video_vlogger_gallery_heading', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magnais ipsum suspendisse' );

        $professional_video_vlogger_latest_post_category_1 = wp_create_category('Blog Post');
            set_theme_mod( 'professional_video_vlogger_gallery_category', 'Blog Post' ); 

        for($i=1; $i<=4; $i++) {

            $title=array('Do Yoga Once a Week these Keep Your Body the Fit', 'This Camera is a Type of Camera that has high Resolution', 'There is Always an and the Appetite There is Always haedes an Appetite for a Menu Like this for a Menu Like this','This Camera is a Type of Camera that has high Resolution');

            // Create post object
            $professional_video_vlogger_my_post = array(
                'post_title'    => wp_strip_all_tags( $title[$i-1] ),
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($professional_video_vlogger_latest_post_category_1) 
            );

            // Insert the post into the database
            $professional_video_vlogger_post_id = wp_insert_post( $professional_video_vlogger_my_post );

            $professional_video_vlogger_image_url = get_template_directory_uri().'/assets/images/trending-video'.$i.'.png';

            $professional_video_vlogger_image_name= 'trending-video'.$i.'.png';
            $professional_video_vlogger_upload_dir = wp_upload_dir(); 
            // Set upload folder
            $professional_video_vlogger_image_data_1 = file_get_contents($professional_video_vlogger_image_url); 
             
            // Get image data
            $professional_video_vlogger_unique_file_name = wp_unique_filename( $professional_video_vlogger_upload_dir['path'], $professional_video_vlogger_image_name ); 
            // Generate unique name
            $filename= basename( $professional_video_vlogger_unique_file_name ); 
            // Create image file name
            // Check folder permission and define file location
            if( wp_mkdir_p( $professional_video_vlogger_upload_dir['path'] ) ) {
                $file = $professional_video_vlogger_upload_dir['path'] . '/' . $filename;
            } else {
                $file = $professional_video_vlogger_upload_dir['basedir'] . '/' . $filename;
            }

            // Create the image  file on the server
            if ( ! function_exists( 'WP_Filesystem' ) ) {
                require_once( ABSPATH . 'wp-admin/includes/file.php' );
            }
            
            WP_Filesystem();
            global $wp_filesystem;
            
            if ( ! $wp_filesystem->put_contents( $file, $professional_video_vlogger_image_data_1, FS_CHMOD_FILE ) ) {
                wp_die( 'Error saving file!' );
            }

            $professional_video_vlogger_wp_filetype = wp_check_filetype( $filename, null );
            $professional_video_vlogger_attachment = array(
                'post_mime_type' => $professional_video_vlogger_wp_filetype['type'],
                'post_title'     => sanitize_file_name( $filename ),
                'post_content'   => '',
                'post_type'     => 'post',
                'post_status'    => 'inherit'
            );
            $professional_video_vlogger_attach_id = wp_insert_attachment( $professional_video_vlogger_attachment, $file, $professional_video_vlogger_post_id );
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $professional_video_vlogger_attach_data = wp_generate_attachment_metadata( $professional_video_vlogger_attach_id, $file );
                wp_update_attachment_metadata( $professional_video_vlogger_attach_id, $professional_video_vlogger_attach_data );
                set_post_thumbnail( $professional_video_vlogger_post_id, $professional_video_vlogger_attach_id );
        }

        //--------------------------------------//

	 }
    }

	// Instantiate the class and call its methods
    $demo_importer = new ProfessionalVideoVloggerDemoImporter();
    $demo_importer->setup_widgets();
    $demo_importer->professional_video_vlogger_customizer_primary_menu();
}
		
?>