<?php

class Whizzie {

	public function __construct() {
		$this->init();
	}

	public function init()
	{
	
	}

	public static function film_production_setup_widgets(){

    /* Create Menu */
            $film_production_menuname  = 'Main Menu';
            $film_production_location  = 'main-menu';

            $film_production_menu = wp_get_nav_menu_object( $film_production_menuname );

            if ( ! $film_production_menu ) {
            $film_production_menu_id = wp_create_nav_menu( $film_production_menuname );

           // Home Page 
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'film-production' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

			// About Us Page 
			$film_production_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'About Us',
			'post_status' => 'publish',
			) );

			if ( $film_production_about_id ) {
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
			'menu-item-title'     => 'About Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $film_production_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Services Page 
			$film_production_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Services',
			'post_status' => 'publish',
			) );

			if ( $film_production_about_id ) {
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
			'menu-item-title'     => 'Services',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $film_production_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Production Page 
			$film_production_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Production',
			'post_status' => 'publish',
			) );

			if ( $film_production_about_id ) {
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
			'menu-item-title'     => 'Production',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $film_production_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Gallery Page 
			$film_production_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Gallery',
			'post_status' => 'publish',
			) );

			if ( $film_production_about_id ) {
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
			'menu-item-title'     => 'Gallery',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $film_production_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}
            
			// Team Page 
			$film_production_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Team',
			'post_status' => 'publish',
			) );

			if ( $film_production_about_id ) {
			wp_update_nav_menu_item( $film_production_menu_id, 0, array(
			'menu-item-title'     => 'Team',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $film_production_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

            // Create Blog Page 
            $film_production_blog_page_title = 'Blog';

             $film_production_blog_page_query = new WP_Query(array(
            'post_type'      => 'page',
            'name'           => sanitize_title($film_production_blog_page_title),
            'post_status'    => 'publish',
            'posts_per_page' => 1
            ));
            if (!$film_production_blog_page_query->have_posts()) {
            $film_production_blog_page = array(
            'post_type'   => 'page',
            'post_title'  => $film_production_blog_page_title,
            'post_status' => 'publish',
            'post_author' => 1,
            );
            $film_production_blog_page_id = wp_insert_post($film_production_blog_page);
            update_option('page_for_posts', $film_production_blog_page_id);

            wp_update_nav_menu_item($film_production_menu_id, 0, array(
            'menu-item-title'      => __('Blog', 'film-production'),
            'menu-item-url'        => get_permalink($film_production_blog_page_id),
            'menu-item-status'     => 'publish',
            'menu-item-object-id'  => $film_production_blog_page_id,
            'menu-item-object'     => 'page',
            'menu-item-type'       => 'post_type',
            ));
            }
            
			/* Assign Menu Location */
			$film_production_locations = get_theme_mod( 'nav_menu_locations', array() );
			$film_production_locations[ $film_production_location ] = $film_production_menu_id;
			set_theme_mod( 'nav_menu_locations', $film_production_locations );
		}

		// select Post Box
		$film_production_title_array = array("Moments that define aur craft", "Moments that define aur craft", "Moments that define aur craft");

		// Ensure the category exists
		$film_production_category_name = 'Services';
		$film_production_category_id = get_cat_ID($film_production_category_name);

		if ($film_production_category_id == 0) {
			$film_production_category_id = wp_create_category($film_production_category_name);
		}

		for ($film_production_i = 1; $film_production_i <= 3; $film_production_i++) {
			// Create post
			$film_production_title = $film_production_title_array[$film_production_i - 1];
			$film_production_content = 'Step into the world behind the camera-from breathtaking sets.';

			$film_production_my_post = array(
				'post_title'    => wp_strip_all_tags($film_production_title),
				'post_content'  => $film_production_content,
				'post_status'   => 'publish',
				'post_type'     => 'post',
				'post_category' => array($film_production_category_id),
			);

			$film_production_post_id = wp_insert_post($film_production_my_post);

			// Get image URL
			$film_production_image_url = get_template_directory_uri() . '/assets/images/image' . $film_production_i . '.png';
			$film_production_image_data = wp_remote_get($film_production_image_url);

			if (!is_wp_error($film_production_image_data)) {
				$film_production_image_body = wp_remote_retrieve_body($film_production_image_data);
				$film_production_upload_dir = wp_upload_dir();
				$film_production_image_name = 'image' . $film_production_i . '.png';
				$uploaded_file = wp_upload_bits($film_production_image_name, null, $film_production_image_body);

				if (!$uploaded_file['error']) {
					$attachment = array(
						'post_mime_type' => $uploaded_file['type'],
						'post_title'     => sanitize_file_name($film_production_image_name),
						'post_content'   => '',
						'post_status'    => 'inherit',
					);
					$film_production_attach_id = wp_insert_attachment($attachment, $uploaded_file['file'], $film_production_post_id);
					require_once(ABSPATH . 'wp-admin/includes/image.php');
					$film_production_attach_data = wp_generate_attachment_metadata($film_production_attach_id, $uploaded_file['file']);
					wp_update_attachment_metadata($film_production_attach_id, $film_production_attach_data);
					set_post_thumbnail($film_production_post_id, $film_production_attach_id);
				}
			}
		}
	}
}
 