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

        public function engineering_manufacturing_customizer_primary_menu() {
            // Create Primary Menu
            $engineering_manufacturing_themename = 'Engineering Manufacturing'; // Define the theme name
            $engineering_manufacturing_menuname = $engineering_manufacturing_themename . 'Main Menus';
            $engineering_manufacturing_bpmenulocation = 'main-menu';
            $engineering_manufacturing_menu_exists = wp_get_nav_menu_object($engineering_manufacturing_menuname);

            if (!$engineering_manufacturing_menu_exists) {
                $engineering_manufacturing_menu_id = wp_create_nav_menu($engineering_manufacturing_menuname);

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

                wp_update_nav_menu_item($engineering_manufacturing_menu_id, 0, array(
                    'menu-item-title' => __('Features', 'engineering-manufacturing'),
                    'menu-item-classes' => 'features',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Features')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($engineering_manufacturing_menu_id, 0, array(
                    'menu-item-title' => __('Products', 'engineering-manufacturing'),
                    'menu-item-classes' => 'products',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Products')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($engineering_manufacturing_menu_id, 0, array(
                    'menu-item-title' => __('Marketing', 'engineering-manufacturing'),
                    'menu-item-classes' => 'marketing',
                    'menu-item-url' => get_permalink(get_page_id_by_title('Marketing')),
                    'menu-item-status' => 'publish',
                ));

                wp_update_nav_menu_item($engineering_manufacturing_menu_id, 0, array(
                    'menu-item-title' => __('Contact Us', 'engineering-manufacturing'),
                    '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($engineering_manufacturing_bpmenulocation)) {
                    $locations = get_theme_mod('nav_menu_locations');
                    $locations[$engineering_manufacturing_bpmenulocation] = $engineering_manufacturing_menu_id;
                    set_theme_mod('nav_menu_locations', $locations);
                }
            }
        }

        public function setup_widgets() {

        $engineering_manufacturing_home_id='';
        $engineering_manufacturing_home_content = '';
        $engineering_manufacturing_home_title = 'Home';
        $engineering_manufacturing_home = array(
            'post_type' => 'page',
            'post_title' => $engineering_manufacturing_home_title,
            'post_content' => $engineering_manufacturing_home_content,
            'post_status' => 'publish',
            'post_author' => 1,
            'post_slug' => 'home'
        );
        $engineering_manufacturing_home_id = wp_insert_post($engineering_manufacturing_home);

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

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

                        // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Features';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'features',
                    '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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

                        // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Products';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check  == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'products',
                    '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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

                         // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Support';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check  == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'support',
                    '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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

                         // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Pricing';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check  == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'pricing',
                    '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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

                                     // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Marketing';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check  == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_blog_title,
                    'post_status' => 'publish',
                    'post_author' => 1,
                    'post_name' => 'marketing',
                    '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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

                                                 // Create a Posts Page
            $engineering_manufacturing_blog_title = 'Contact Us';
            $engineering_manufacturing_blog_check = get_page_id_by_title($engineering_manufacturing_blog_title);

            if ($engineering_manufacturing_blog_check  == 1) {
                $engineering_manufacturing_blog = array(
                    'post_type' => 'page',
                    'post_title' => $engineering_manufacturing_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."',
                );
                $engineering_manufacturing_blog_id = wp_insert_post($engineering_manufacturing_blog);

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

		//---Header--//

		set_theme_mod( 'engineering_manufacturing_header_timing', 'Monday - Saturday 8AM - 7PM / Closed on Weekends');

        set_theme_mod( 'engineering_manufacturing_header_link1_text', 'News & Media');

        set_theme_mod( 'engineering_manufacturing_header_link1_url', '#');

        set_theme_mod( 'engineering_manufacturing_header_link2_text', 'Careers');

        set_theme_mod( 'engineering_manufacturing_header_link1_url', '#');

        set_theme_mod('engineering_manufacturing_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" => "#"
            )
        ));
            
        set_theme_mod( 'engineering_manufacturing_header_email', 'engineerexample@mail.com');

        set_theme_mod( 'engineering_manufacturing_header_phone_number', '+81 65754-87765');


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

		set_theme_mod( 'engineering_manufacturing_blog_box_enable', true);

        set_theme_mod( 'engineering_manufacturing_slider_extra_heading', 'TRENDING we are professional & established company');

		set_theme_mod( 'engineering_manufacturing_blog_slide_number', '3' );
		$engineering_manufacturing_latest_post_category = wp_create_category('Slider Post');
			set_theme_mod( 'engineering_manufacturing_blog_slide_category', 'Slider Post' ); 

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

            $title=array('We will provide the best Industrial service', 'The greatest industrial service will be offered by us.', 'We will offer the greatest industrial service.');
			$content = 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliquai suspendisse.';

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

			// Insert the post into the database
			$engineering_manufacturing_post_id = wp_insert_post( $engineering_manufacturing_my_post );

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

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

			if ( ! function_exists( 'WP_Filesystem' ) ) {
                    require_once( ABSPATH . 'wp-admin/includes/file.php' );
                }
                
                WP_Filesystem();
                global $wp_filesystem;
                
                if ( ! $wp_filesystem->put_contents( $file, $engineering_manufacturing_image_data, FS_CHMOD_FILE ) ) {
                    wp_die( 'Error saving file!' );
                }
			$engineering_manufacturing_wp_filetype = wp_check_filetype( $filename, null );
			$engineering_manufacturing_attachment = array(
				'post_mime_type' => $engineering_manufacturing_wp_filetype['type'],
				'post_title'     => sanitize_file_name( $filename ),
				'post_content'   => '',
				'post_type'     => 'post',
				'post_status'    => 'inherit'
			);
			$engineering_manufacturing_attach_id = wp_insert_attachment( $engineering_manufacturing_attachment, $file, $engineering_manufacturing_post_id );
			require_once(ABSPATH . 'wp-admin/includes/image.php');
			$engineering_manufacturing_attach_data = wp_generate_attachment_metadata( $engineering_manufacturing_attach_id, $file );
				wp_update_attachment_metadata( $engineering_manufacturing_attach_id, $engineering_manufacturing_attach_data );
				set_post_thumbnail( $engineering_manufacturing_post_id, $engineering_manufacturing_attach_id );
		}

		//-----Our Services-----//

		set_theme_mod( 'engineering_manufacturing_services_section_enable', true);

        set_theme_mod( 'engineering_manufacturing_services_heading', 'We Are provide Best Services For Our Clients');

        $engineering_manufacturing_latest_post_category = wp_create_category('Services Post');
            set_theme_mod( 'engineering_manufacturing_services_category', 'Services Post' ); 

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

            $title=array('Agricultural Processing', 'Chemical Research', 'Mechanical Engineering');
            $content = 'Consectetur adipiscing elit, sed do eiusmod andes tempor incididunt ut labore et dolore magna aliquauis ipsum.';

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

            // Insert the post into the database
            $engineering_manufacturing_post_id = wp_insert_post( $engineering_manufacturing_my_post );

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

            $engineering_manufacturing_image_name= 'services'.$i.'.png';
            $engineering_manufacturing_upload_dir       = wp_upload_dir(); 
            // Set upload folder
            $engineering_manufacturing_image_data       = file_get_contents($engineering_manufacturing_image_url); 
             
            // Get image data
            $engineering_manufacturing_unique_file_name = wp_unique_filename( $engineering_manufacturing_upload_dir['path'], $engineering_manufacturing_image_name ); 
            // Generate unique name
            $filename= basename( $engineering_manufacturing_unique_file_name ); 
            // Create image file name
            // Check folder permission and define file location
            if( wp_mkdir_p( $engineering_manufacturing_upload_dir['path'] ) ) {
                $file = $engineering_manufacturing_upload_dir['path'] . '/' . $filename;
            } else {
                $file = $engineering_manufacturing_upload_dir['basedir'] . '/' . $filename;
            }

            if ( ! function_exists( 'WP_Filesystem' ) ) {
                    require_once( ABSPATH . 'wp-admin/includes/file.php' );
                }
                
                WP_Filesystem();
                global $wp_filesystem;
                
                if ( ! $wp_filesystem->put_contents( $file, $engineering_manufacturing_image_data, FS_CHMOD_FILE ) ) {
                    wp_die( 'Error saving file!' );
                }
            $engineering_manufacturing_wp_filetype = wp_check_filetype( $filename, null );
            $engineering_manufacturing_attachment = array(
                'post_mime_type' => $engineering_manufacturing_wp_filetype['type'],
                'post_title'     => sanitize_file_name( $filename ),
                'post_content'   => '',
                'post_type'     => 'post',
                'post_status'    => 'inherit'
            );
            $engineering_manufacturing_attach_id = wp_insert_attachment( $engineering_manufacturing_attachment, $file, $engineering_manufacturing_post_id );
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $engineering_manufacturing_attach_data = wp_generate_attachment_metadata( $engineering_manufacturing_attach_id, $file );
                wp_update_attachment_metadata( $engineering_manufacturing_attach_id, $engineering_manufacturing_attach_data );
                set_post_thumbnail( $engineering_manufacturing_post_id, $engineering_manufacturing_attach_id );
        }
    }
    }
	// Instantiate the class and call its methods
    $demo_importer = new EngineeringManufacturingDemoImporter();
    $demo_importer->setup_widgets();
    $demo_importer->engineering_manufacturing_customizer_primary_menu();
	}
?>