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

        public function professional_blogger_customizer_primary_menu() {
            // Create Primary Menu
            $professional_blogger_themename = 'Professional Blogger'; // Define the theme name
            $professional_blogger_menuname = $professional_blogger_themename . 'Left Menu';
            $professional_blogger_bpmenulocation = 'main-menu-leftside';
            $professional_blogger_menu_exists = wp_get_nav_menu_object($professional_blogger_menuname);

            if (!$professional_blogger_menu_exists) {
                $professional_blogger_menu_id = wp_create_nav_menu($professional_blogger_menuname);

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

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Health', 'professional-blogger'),
                    'menu-item-classes' => 'health',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Health')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Life Style', 'professional-blogger'),
                    'menu-item-classes' => 'life-style',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Life Style')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Music', 'professional-blogger'),
                    'menu-item-classes' => 'music',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Music')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Technology', 'professional-blogger'),
                    'menu-item-classes' => 'technology',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Technology')),
                    'menu-item-status' => 'publish',
                ));

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

            public function professional_blogger_customizer_primary_menu_2() {
            // Create Primary Menu
            $professional_blogger_themename = 'Professional Blogger'; // Define the theme name
            $professional_blogger_menuname = $professional_blogger_themename . 'Right Menu';
            $professional_blogger_bpmenulocation = 'main-menu-rightside';
            $professional_blogger_menu_exists = wp_get_nav_menu_object($professional_blogger_menuname);

            if (!$professional_blogger_menu_exists) {
                $professional_blogger_menu_id = wp_create_nav_menu($professional_blogger_menuname);

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Travel', 'professional-blogger'),
                    'menu-item-classes' => 'travel',
                    'menu-item-url' => get_permalink(get_page_id_by_title('travel')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Cart', 'professional-blogger'),
                    'menu-item-classes' => 'cart',
                    'menu-item-url' => get_permalink(get_page_id_by_title('cart')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Checkout', 'professional-blogger'),
                    'menu-item-classes' => 'checkout',
                    'menu-item-url' => get_permalink(get_page_id_by_title('checkout')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($professional_blogger_menu_id, 0, array(
                    'menu-item-title' => __('Account', 'professional-blogger'),
                    'menu-item-classes' => 'account',
                    'menu-item-url' => get_permalink(get_page_id_by_title('account')),
                    'menu-item-status' => 'publish',
                ));

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

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

        public function setup_widgets() {

        $professional_blogger_home_id='';
        $professional_blogger_home_content = '';
        $professional_blogger_home_title = 'Home';
        $professional_blogger_home = array(
            'post_type' => 'page',
            'post_title' => $professional_blogger_home_title,
            'post_content' => $professional_blogger_home_content,
            'post_status' => 'publish',
            'post_author' => 1,
            'post_slug' => 'home'
        );
        $professional_blogger_home_id = wp_insert_post($professional_blogger_home);

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

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

                        // Create a Posts Page
            $professional_blogger_blog_title = 'Health';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'health',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                        // Create a Posts Page
            $professional_blogger_blog_title = 'Life Style';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'life-style',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                         // Create a Posts Page
            $professional_blogger_blog_title = 'Music';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'music',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                         // Create a Posts Page
            $professional_blogger_blog_title = 'Technology';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'technology',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                                     // Create a Posts Page
            $professional_blogger_blog_title = 'Travel';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'travel',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                                     // Create a Posts Page
            $professional_blogger_blog_title = 'Cart';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'cart',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                                     // Create a Posts Page
            $professional_blogger_blog_title = 'Account';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'account',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

            // Create a Posts Page
            $professional_blogger_blog_title = 'Checkout';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'checkout',
                    '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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

                                     // Create a Posts Page
            $professional_blogger_blog_title = 'Blog';
            $professional_blogger_blog_check = get_page_id_by_title($professional_blogger_blog_title);

            if ($professional_blogger_blog_check  == 1) {
                $professional_blogger_blog = array(
                    'post_type' => 'page',
                    'post_title' => $professional_blogger_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_blogger_blog_id = wp_insert_post($professional_blogger_blog);

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

		//---Header--//

        set_theme_mod( 'professional_blogger_topbar_text', '6 Quick And Easy Recipes That Will Make People Believe You Can Cook');

        set_theme_mod('professional_blogger_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_blogger_blog_box_enable', true);

		set_theme_mod( 'professional_blogger_blog_slide_number', '3' );
		$professional_blogger_latest_post_category = wp_create_category('Slider Post');
			set_theme_mod( 'professional_blogger_blog_slide_category', 'Slider Post' ); 

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

			$content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliquat enim anim veniam, quis nostrud exercitation..';

			$tittle_text=array('Rocket Lab mission fails shortly after launch', 'The mission of Rocket Lab fails soon after launch.', 'Mission failure at Rocket Lab soon after takeoff');

			// Create post object
			$professional_blogger_my_post = array(
				'post_title'    => wp_strip_all_tags( $tittle_text[$i-1] ),
				'post_content'  => $content,
				'post_status'   => 'publish',
				'post_type'     => 'post',
				'post_category' => array($professional_blogger_latest_post_category) 
			);

			// Insert the post into the database
			$professional_blogger_post_id = wp_insert_post( $professional_blogger_my_post );

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

			$professional_blogger_image_name= 'slider'.$i.'.png';
			$professional_blogger_upload_dir = wp_upload_dir(); 
			// Set upload folder
			$professional_blogger_image_data = file_get_contents($professional_blogger_image_url); 
			 
			// Get image data
			$professional_blogger_unique_file_name = wp_unique_filename( $professional_blogger_upload_dir['path'], $professional_blogger_image_name ); 
			// Generate unique name
			$filename= basename( $professional_blogger_unique_file_name ); 
			// Create image file name
			// Check folder permission and define file location
			if( wp_mkdir_p( $professional_blogger_upload_dir['path'] ) ) {
				$file = $professional_blogger_upload_dir['path'] . '/' . $filename;
			} else {
				$file = $professional_blogger_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_blogger_image_data, FS_CHMOD_FILE ) ) {
                wp_die( 'Error saving file!' );
            }

			$professional_blogger_wp_filetype = wp_check_filetype( $filename, null );
			$professional_blogger_attachment = array(
				'post_mime_type' => $professional_blogger_wp_filetype['type'],
				'post_title'     => sanitize_file_name( $filename ),
				'post_content'   => '',
				'post_type'     => 'post',
				'post_status'    => 'inherit'
			);
			$professional_blogger_attach_id = wp_insert_attachment( $professional_blogger_attachment, $file, $professional_blogger_post_id );
			require_once(ABSPATH . 'wp-admin/includes/image.php');
			$professional_blogger_attach_data = wp_generate_attachment_metadata( $professional_blogger_attach_id, $file );
				wp_update_attachment_metadata( $professional_blogger_attach_id, $professional_blogger_attach_data );
				set_post_thumbnail( $professional_blogger_post_id, $professional_blogger_attach_id );
		}


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

        set_theme_mod( 'professional_blogger_trending_section_enable', true);

        set_theme_mod( 'professional_blogger_trending_heading', 'Trending News' );

        set_theme_mod( 'professional_blogger_header_button_link', '#' );

        set_theme_mod( 'professional_blogger_trending_number', '3' );
        $professional_blogger_latest_post_category_1 = wp_create_category('Blog Post');
            set_theme_mod( 'professional_blogger_trending_category', 'Blog Post' ); 

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

            $content = 'Lorem ipsum dolor sit ame consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.';

            $tittle_cat=array('Rocket Lab mission fails shortly after launch', 'The mission of Rocket Lab fails soon after launch.', 'Mission failure at Rocket Lab soon after takeoff');

            // Create post object
            $professional_blogger_my_post = array(
                'post_title'    => wp_strip_all_tags( $tittle_cat[$i-1] ),
                'post_content'  => $content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($professional_blogger_latest_post_category_1) 
            );

            // Insert the post into the database
            $professional_blogger_post_id = wp_insert_post( $professional_blogger_my_post );

            $professional_blogger_image_url = get_template_directory_uri().'/assets/images/services'.$i.'.png';

            $professional_blogger_image_name= 'services'.$i.'.png';
            $professional_blogger_upload_dir = wp_upload_dir(); 
            // Set upload folder
            $professional_blogger_image_data_1 = file_get_contents($professional_blogger_image_url); 
             
            // Get image data
            $professional_blogger_unique_file_name = wp_unique_filename( $professional_blogger_upload_dir['path'], $professional_blogger_image_name ); 
            // Generate unique name
            $filename= basename( $professional_blogger_unique_file_name ); 
            // Create image file name
            // Check folder permission and define file location
            if( wp_mkdir_p( $professional_blogger_upload_dir['path'] ) ) {
                $file = $professional_blogger_upload_dir['path'] . '/' . $filename;
            } else {
                $file = $professional_blogger_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_blogger_image_data_1, FS_CHMOD_FILE ) ) {
                wp_die( 'Error saving file!' );
            }

            $professional_blogger_wp_filetype = wp_check_filetype( $filename, null );
            $professional_blogger_attachment = array(
                'post_mime_type' => $professional_blogger_wp_filetype['type'],
                'post_title'     => sanitize_file_name( $filename ),
                'post_content'   => '',
                'post_type'     => 'post',
                'post_status'    => 'inherit'
            );
            $professional_blogger_attach_id = wp_insert_attachment( $professional_blogger_attachment, $file, $professional_blogger_post_id );
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $professional_blogger_attach_data = wp_generate_attachment_metadata( $professional_blogger_attach_id, $file );
                wp_update_attachment_metadata( $professional_blogger_attach_id, $professional_blogger_attach_data );
                set_post_thumbnail( $professional_blogger_post_id, $professional_blogger_attach_id );
        }




        //----- Our Products Section----//
	 }
    }

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