<?php //to use wp udpate plugin

    $home_id=''; $blog_id=''; $page_id=''; $about_id='';


    // Function to check if a page with a specific title exists
    function page_exists_by_title($title) {
      $page_query = new WP_Query(array(
          'post_type'   => 'page',
          'title'       => $title,
          'post_status' => 'publish',
          'numberposts' => 1
      ));
      
      if ($page_query->have_posts()) {
          // Return the ID of the first matching page
          $page = $page_query->posts[0];
          return $page->ID;
      }
    
      return false; // Return false if no page found
    }

    //Homepage
    $home_title = 'Home';
    if (!page_exists_by_title($home_title)) {
      $home_content = '';
      $home = array(
        'post_type'    => 'page',
        'post_title'   => $home_title,
        'post_content' => $home_content,
        'post_status'  => 'publish',
        'post_author'  => 1,
        'post_name'    => 'home'
      );

      $home_id = wp_insert_post($home);
      
      // Set the home page template
      add_post_meta($home_id, '_wp_page_template', 'page-template/custom-home-page.php');
      
      // Set the static front page
      update_option('page_on_front', $home_id);
      update_option('show_on_front', 'page');

    }else {
      // Get the ID of the existing page
      $home_id = page_exists_by_title($home_title);

      // Set the home page template
      add_post_meta($home_id, '_wp_page_template', 'page-template/custom-home-page.php');
      
      // Set the static front page
      update_option('page_on_front', $home_id);
      update_option('show_on_front', 'page');
    }
    


    // Create a Page if it doesn't exist
    if ( !page_exists_by_title('Page') ) {
      $page_title = 'Page';
      $content = 'Te obtinuit ut adepto satis somno. Aliisque institoribus iter deliciae vivet vita. Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semel';

      $ot_page = array(
        'post_type'     => 'page',
        'post_title'    => $page_title,
        'post_content'  => $content,
        'post_status'   => 'publish',
        'post_author'   => 1,
        'post_name'     => 'page'
      );
      $page_id = wp_insert_post($ot_page);
    }else {
      // Get the ID of the existing page
      $ot_page = page_exists_by_title('Page');
    }

    if ( !page_exists_by_title('Page Left Sidebar') ) {
      $page_title = 'Page Left Sidebar';
      $content = 'Te obtinuit ut adepto satis somno. Aliisque institoribus iter deliciae vivet vita. Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semelTe obtinuit ut adepto satis somno. Aliisque institoribus iter deliciae vivet vita. Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semel.Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semel.';

      $ot_page = array(
        'post_type'     => 'page',
        'post_title'    => $page_title,
        'post_content'  => $content,
        'post_status'   => 'publish',
        'post_author'   => 1,
        'post_name'     => 'page-left'
      );
      $page_id = wp_insert_post($ot_page);

      // Set the page template
      add_post_meta($page_id, '_wp_page_template', 'page-template/left-sidebar.php');
    }else {
      // Get the ID of the existing page
      $ot_page = page_exists_by_title('Page Left Sidebar');
    }

    if ( !page_exists_by_title('Page Right Sidebar') ) {
      $page_title = 'Page Right Sidebar';
      $content = 'Te obtinuit ut adepto satis somno. Aliisque institoribus iter deliciae vivet vita. Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semelTe obtinuit ut adepto satis somno. Aliisque institoribus iter deliciae vivet vita. Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semel.Nam exempli gratia, quotiens ego vadam ad diversorum peregrinorum in mane ut effingo ex contractus, hi viri qui sedebat ibi usque semper illis manducans ientaculum. Solum cum bulla ut debui; EGO youd adepto a macula proiciendi. Sed quis scit si forte quod esset optima res pro me. sicut ea quae sentio. Qui vellem cadunt off ius desk ejus! Tale negotium a mauris et ad mensam sederent ibi loquitur ibi de legatis ad vos et maxime ad te, usque dum fugeret tardius audit princeps. Bene tamen fiduciam Ego got off semel.';

      $ot_page = array(
        'post_type'     => 'page',
        'post_title'    => $page_title,
        'post_content'  => $content,
        'post_status'   => 'publish',
        'post_author'   => 1,
        'post_name'     => 'page-right'
      );
      $page_id = wp_insert_post($ot_page);

      // Set the page template
      add_post_meta($page_id, '_wp_page_template', 'page-template/right-sidebar.php');
    }else {
      // Get the ID of the existing page
      $ot_page = page_exists_by_title('Page Right Sidebar');
    }

    // ------- Create Left Menu --------
    $menuname =  'Main Menu';
    $bpmenulocation = 'primary';
    $menu_exists = wp_get_nav_menu_object( $menuname );

    if (!$menu_exists) {
      // Create the menu
      $menu_id = wp_create_nav_menu($menuname);

      // Add the HOME item
      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'  => __('Home', 'yoga-meditation'),
          'menu-item-classes' => 'home',
          'menu-item-url'     => home_url('/index.php/home/'),
          'menu-item-status'  => 'publish'
      ));

      // Add the PAGE item
      $parent_page_item_id = wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'  => __('Pages', 'yoga-meditation'),
          'menu-item-classes' => 'page',
          'menu-item-url'     => home_url('/index.php/page/'),
          'menu-item-status'  => 'publish'
      ));

      // Add the Page Left Sidebar item as a child of PAGE
      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'   => __('Page Left Sidebar', 'yoga-meditation'),
          'menu-item-classes' => 'page-left',
          'menu-item-url'     => home_url('/index.php/page-left/'),
          'menu-item-status'  => 'publish',
          'menu-item-parent-id' => $parent_page_item_id
      ));

      // Add the Page Right Sidebar item as a child of PAGE
      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'   => __('Page Right Sidebar', 'yoga-meditation'),
          'menu-item-classes' => 'page-right',
          'menu-item-url'     => home_url('/index.php/page-right/'),
          'menu-item-status'  => 'publish',
          'menu-item-parent-id' => $parent_page_item_id
      ));

      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'  => __('About Us', 'yoga-meditation'),
          'menu-item-classes' => 'aboutus',
          'menu-item-url'     => '#',
          'menu-item-status'  => 'publish'
      ));

      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'  => __('Classes', 'yoga-meditation'),
          'menu-item-classes' => 'classes',
          'menu-item-url'     => '#',
          'menu-item-status'  => 'publish'
      ));

      wp_update_nav_menu_item($menu_id, 0, array(
          'menu-item-title'  => __('Trainers', 'yoga-meditation'),
          'menu-item-classes' => 'trainers',
          'menu-item-url'     => '#',
          'menu-item-status'  => 'publish'
      ));
      
      // Assign the menu to the desired location if not already assigned
      if (!has_nav_menu($bpmenulocation)) {
          $locations = get_theme_mod('nav_menu_locations');
          $locations[$bpmenulocation] = $menu_id;
          set_theme_mod('nav_menu_locations', $locations);
      }
    }
       
    // --------Header------------------------

    set_theme_mod( 'yoga_meditation_email', 'support@example.com' ); 

    set_theme_mod( 'yoga_studio_phone', '+123-456-78-09' ); 

    set_theme_mod( 'yoga_studio_address', '1810 Way King Street,5th Avenue Miami' ); 

    set_theme_mod( 'yoga_studio_button_link', '#' );

    set_theme_mod( 'yoga_studio_button_text', 'Enquiry' );

    // --------Header------------------------

    set_theme_mod( 'yoga_studio_twitter', 'https://www.twitter.com/' );

    set_theme_mod( 'yoga_studio_linkedin', 'https://www.linkedin.com/' );

    set_theme_mod( 'yoga_studio_youtube', 'https://www.youtube.com/' );

    set_theme_mod( 'yoga_studio_instagram', 'https://www.instagram.com/' );

    set_theme_mod( 'yoga_studio_facebook', 'https://www.facebook.com/' );

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

    set_theme_mod( 'yoga_studio_post_setting', '4' );

    $slider_category = wp_create_category('Slider'); 

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

      $title = '"Yoga is the journey of the self, through the self, to the self."';
      $content = 'Etiam rhoncus. Maecenas tempus,telluseget condimenttum rhoncus,sem quam semper libero,sit amet adipiscing sem neque sed ipsum consectetuer adipiscing elit';

      // Create post object
      $yoga_studio_my_post = array(
       'post_title'    => wp_strip_all_tags( $title ),
       'post_content'  => $content,
       'post_status'   => 'publish',
       'post_type'     => 'post',
       'post_category' => array($slider_category) 
      );

      $yoga_studio_slider_post_id = wp_insert_post($yoga_studio_my_post);

      $yoga_studio_post_image_url = get_stylesheet_directory_uri().'/assets/images/slider.jpg';

      $yoga_studio_image_name = 'slider.jpg';
      $yoga_studio_upload_dir       = wp_upload_dir(); 
      // Set upload folder
      $yoga_studio_image_data       = file_get_contents($yoga_studio_post_image_url); 
       
      // Get image data
      $yoga_studio_unique_file_name = wp_unique_filename( $yoga_studio_upload_dir['path'], $yoga_studio_image_name ); 
      // Generate unique name
      $filename= basename( $yoga_studio_unique_file_name ); 
      // Create image file name
      // Check folder permission and define file location
      if( wp_mkdir_p( $yoga_studio_upload_dir['path'] ) ) {
          $file = $yoga_studio_upload_dir['path'] . '/' . $filename;
      } else {
          $file = $yoga_studio_upload_dir['basedir'] . '/' . $filename;
      }
      file_put_contents( $file, $yoga_studio_image_data );
      $wp_filetype = wp_check_filetype( $filename, null );
      $yoga_studio_attachment = array(
          'post_mime_type' => $wp_filetype['type'],
          'post_title'     => sanitize_file_name( $filename ),
          'post_content'   => '',
          'post_type'     => 'post',
          'post_status'    => 'inherit'
      );
      $attach_id = wp_insert_attachment( $yoga_studio_attachment, $file, $yoga_studio_slider_post_id );
      require_once(ABSPATH . 'wp-admin/includes/image.php');
      $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
          wp_update_attachment_metadata( $attach_id, $attach_data );
          set_post_thumbnail( $yoga_studio_slider_post_id, $attach_id );

    }

    set_theme_mod( 'yoga_studio_post_setting', 'Slider' );

    //-------------- Service-----------------------

    set_theme_mod( 'yoga_studio_services_section_title', 'OUR SERVICES' ); 

    set_theme_mod( 'yoga_studio_services_section_text', 'Choose What You Want' ); 

    $yoga_studio_service_category = wp_create_category('Our Services'); 

    $yoga_studio_service_title=array('Vinyasa Yoga','Basic Yoga','Meditation Yoga');

    set_theme_mod( 'yoga_studio_service_count', '3' );

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

      $title = $yoga_studio_service_title[$i-1];
      $content = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys 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
      $yoga_studio_my_post = array(
       'post_title'    => wp_strip_all_tags( $title ),
       'post_content'  => $content,
       'post_status'   => 'publish',
       'post_type'     => 'post',
       'post_category' => array($yoga_studio_service_category),
      );

      $yoga_studio_service_post_id = wp_insert_post($yoga_studio_my_post);

      $yoga_studio_service_post_image_url = get_stylesheet_directory_uri().'/assets/images/service'.$i.'.jpg';

      $yoga_studio_service_image_name = 'service'.$i.'.jpg';
      $yoga_studio_service_project_upload_dir       = wp_upload_dir(); 
      // Set upload folder
      $yoga_studio_service_image_data       = file_get_contents($yoga_studio_service_post_image_url); 
       
      // Get image data
      $yoga_studio_service_unique_file_name = wp_unique_filename( $yoga_studio_service_project_upload_dir['path'], $yoga_studio_service_image_name ); 
      // Generate unique name
      $filename= basename( $yoga_studio_service_unique_file_name ); 
      // Create image file name
      // Check folder permission and define file location
      if( wp_mkdir_p( $yoga_studio_service_project_upload_dir['path'] ) ) {
          $file = $yoga_studio_service_project_upload_dir['path'] . '/' . $filename;
      } else {
          $file = $yoga_studio_service_project_upload_dir['basedir'] . '/' . $filename;
      }
      file_put_contents( $file, $yoga_studio_service_image_data );
      $wp_filetype = wp_check_filetype( $filename, null );
      $yoga_studio_service_attachment = array(
          'post_mime_type' => $wp_filetype['type'],
          'post_title'     => sanitize_file_name( $filename ),
          'post_content'   => '',
          'post_type'     => 'post',
          'post_status'    => 'inherit'
      );
      $attach_id = wp_insert_attachment( $yoga_studio_service_attachment, $file, $yoga_studio_service_post_id );
      require_once(ABSPATH . 'wp-admin/includes/image.php');
      $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
          wp_update_attachment_metadata( $attach_id, $attach_data );
          set_post_thumbnail( $yoga_studio_service_post_id, $attach_id );

    }

    set_theme_mod( 'yoga_studio_category_setting', 'Our Services' );

    //-------------- About-----------------------

    $yoga_meditation_about_title = 'ABOUT US';
    $yoga_meditation_about_content = 'Modern yoga consists of a range of techniques including asanas (postures) and meditation derived from some of the philosophies, teachings and practices of the Yoga school, which is one of the six schools of traditional Hindu philosophies, and organised into a wide variety of schools and denominations. It has been described by Elizabeth de Michelis as having four types, namely: Modern Psych osomatic Yoga, as in The Yoga Institute. which is one of the six schools of traditional Hindu philosophies, and organised into a wide variety of schools and denominations.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).';

    // Create post object
    $yoga_meditation_about_post = array(
     'post_title'    => wp_strip_all_tags( $yoga_meditation_about_title ),
     'post_content'  => $yoga_meditation_about_content,
     'post_status'   => 'publish',
     'post_type'     => 'post',
    );

    $yoga_meditation_about_post_id = wp_insert_post($yoga_meditation_about_post);

      $yoga_meditation_about_image_url = get_template_directory_uri().'/assets/images/slider.jpg';

      $yoga_meditation_about_image_name = 'slider.jpg';
      $yoga_meditation_about_upload_dir       = wp_upload_dir(); 
      // Set upload folder
      $yoga_meditation_about_image_data       = file_get_contents($yoga_meditation_about_image_url); 
       
      // Get image data
      $yoga_meditation_about_unique_file_name = wp_unique_filename( $yoga_meditation_about_upload_dir['path'], $yoga_meditation_about_image_name ); 
      // Generate unique name
      $filename= basename( $yoga_meditation_about_unique_file_name ); 
      // Create image file name
      // Check folder permission and define file location
      if( wp_mkdir_p( $yoga_meditation_about_upload_dir['path'] ) ) {
          $file = $yoga_meditation_about_upload_dir['path'] . '/' . $filename;
      } else {
          $file = $yoga_meditation_about_upload_dir['basedir'] . '/' . $filename;
      }
      file_put_contents( $file, $yoga_meditation_about_image_data );
      $wp_filetype = wp_check_filetype( $filename, null );
      $yoga_meditation_about_attachment = array(
          'post_mime_type' => $wp_filetype['type'],
          'post_title'     => sanitize_file_name( $filename ),
          'post_content'   => '',
          'post_type'     => 'post',
          'post_status'    => 'inherit'
      );
      $attach_id = wp_insert_attachment( $yoga_meditation_about_attachment, $file, $yoga_meditation_about_post_id );
      require_once(ABSPATH . 'wp-admin/includes/image.php');
      $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
          wp_update_attachment_metadata( $attach_id, $attach_data );
          set_post_thumbnail( $yoga_meditation_about_post_id, $attach_id );

    // Set theme mod for each post created
    set_theme_mod('yoga_meditation_about_post_setting', $yoga_meditation_about_post_id);
?>