<?php //to use wp udpate plugin
  $business_office_home_id=''; $business_office_blog_id=''; $business_office_page_id=''; $business_office_about_id='';


  // Function to check if a page with a specific title exists
  function page_exists_by_title($business_office_title) {
    $page_query = new WP_Query(array(
        'post_type'   => 'page',
        'title'       => $business_office_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
  $business_office_home_title = 'Home';
  if (!page_exists_by_title($business_office_home_title)) {
    $business_office_home_content = '';
    $business_office_home = array(
      'post_type'    => 'page',
      'post_title'   => $business_office_home_title,
      'post_content' => $business_office_home_content,
      'post_status'  => 'publish',
      'post_author'  => 1,
      'post_name'    => 'home'
    );

    $business_office_home_id = wp_insert_post($business_office_home);
    
    // Set the home page template
    add_post_meta($business_office_home_id, '_wp_page_template', 'apex-library/homepage-template.php');
    
    // Set the static front page
    update_option('page_on_front', $business_office_home_id);
    update_option('show_on_front', 'page');

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

    // Set the home page template
    add_post_meta($business_office_home_id, '_wp_page_template', 'apex-library/homepage-template.php');
    
    // Set the static front page
    update_option('page_on_front', $business_office_home_id);
    update_option('show_on_front', 'page');
  }

  // Create a posts page and assign the template
  $business_office_blog_title = 'Blog';
  $business_office_blog_check = get_page_by_path('blog');
  if (!$business_office_blog_check) {
    $business_office_blog = array(
      'post_type'    => 'page',
      'post_title'   => $business_office_blog_title,
      'post_status'  => 'publish',
      'post_author'  => 1,
      'post_name'    => 'blog' // Unique slug for the blog page
    );
    $business_office_blog_id = wp_insert_post($business_office_blog);

    // Set the posts page
    if (!is_wp_error($business_office_blog_id)) {
      update_option('page_for_posts', $business_office_blog_id);
    }
  }
  
  // Create a Page if it doesn't exist
  if ( !page_exists_by_title('Page') ) {
    $business_office_page_title = 'Page';
    $business_office_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';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'page'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);
  }else {
    // Get the ID of the existing page
    $business_office_ot_page = page_exists_by_title('Page');
  }

  // Create a About if it doesn't exist
  if ( !page_exists_by_title('About') ) {
    $business_office_page_title = 'About';
    $business_office_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';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'about'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);
  }else {
    // Get the ID of the existing page
    $business_office_ot_page = page_exists_by_title('About');
  }

  // Create a Services if it doesn't exist
  if ( !page_exists_by_title('Services') ) {
    $business_office_page_title = 'Services';
    $business_office_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';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'services'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);
  }else {
    // Get the ID of the existing page
    $business_office_ot_page = page_exists_by_title('Services');
  }

  // Create a Contact if it doesn't exist
  if ( !page_exists_by_title('Contact') ) {
    $business_office_page_title = 'Contact';
    $business_office_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';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'contact'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);
  }else {
    // Get the ID of the existing page
    $business_office_ot_page = page_exists_by_title('Contact');
  }

  if ( !page_exists_by_title('Submenu Page One') ) {
    $business_office_page_title = 'Submenu Page One';
    $business_office_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.';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'submenu-page-one'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);

    // Set the page template
    add_post_meta($business_office_page_id, '_wp_page_template', 'apex-library/left-sidebar.php');
  }else {
    // Get the ID of the existing page
    $business_office_ot_page = page_exists_by_title('Submenu Page One');
  }

  if ( !page_exists_by_title('Subemenu Page Two') ) {
    $business_office_page_title = 'Subemenu Page Two';
    $business_office_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.';

    $business_office_ot_page = array(
      'post_type'     => 'page',
      'post_title'    => $business_office_page_title,
      'post_content'  => $business_office_content,
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_name'     => 'submenu-page-two'
    );
    $business_office_page_id = wp_insert_post($business_office_ot_page);

    // Set the page template
    add_post_meta($business_office_page_id, '_wp_page_template', 'apex-library/right-sidebar.php');
    }else {
      // Get the ID of the existing page
      $business_office_ot_page = page_exists_by_title('Subemenu Page Two');
    }


  // ------- Create Left Menu --------
  $business_office_menuname =  'Main Menu';
  $business_office_bpmenulocation = 'primary_menu';
  $business_office_menu_exists = wp_get_nav_menu_object( $business_office_menuname );

  if (!$business_office_menu_exists) {
    // Create the menu
    $business_office_menu_id = wp_create_nav_menu($business_office_menuname);

    // Add the HOME item
    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'  => __('Home', 'business-office'),
        '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($business_office_menu_id, 0, array(
        'menu-item-title'  => __('Blogs', 'business-office'),
        'menu-item-classes' => 'blog',
        'menu-item-url'     => home_url('/index.php/blog/'),
        'menu-item-status'  => 'publish'
    ));

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

    // Add the Submenu Page One item as a child of PAGE
    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'   => __('Submenu Page One', 'business-office'),
        'menu-item-classes' => 'submenu-page-one',
        'menu-item-url'     => home_url('/index.php/submenu-page-one/'),
        'menu-item-status'  => 'publish',
        'menu-item-parent-id' => $parent_page_item_id
    ));

    // Add the Submenu Page Two item as a child of PAGE
    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'   => __('Submenu Page Two', 'business-office'),
        'menu-item-classes' => 'submenu-page-two',
        'menu-item-url'     => home_url('/index.php/submenu-page-two/'),
        'menu-item-status'  => 'publish',
        'menu-item-parent-id' => $parent_page_item_id
    ));

    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'  => __('About', 'business-office'),
        'menu-item-classes' => 'about',
        'menu-item-url'     => home_url('/index.php/about/'),
        'menu-item-status'  => 'publish'
    ));

    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'  => __('Services', 'business-office'),
        'menu-item-classes' => 'services',
        'menu-item-url'     => home_url('/index.php/services/'),
        'menu-item-status'  => 'publish'
    ));

    wp_update_nav_menu_item($business_office_menu_id, 0, array(
        'menu-item-title'  => __('Contact', 'business-office'),
        'menu-item-classes' => 'contact',
        'menu-item-url'     => home_url('/index.php/contact/'),
        'menu-item-status'  => 'publish'
    ));
    
    // Assign the menu to the desired location if not already assigned
    if (!has_nav_menu($business_office_bpmenulocation)) {
        $business_office_locations = get_theme_mod('nav_menu_locations');
        $business_office_locations[$business_office_bpmenulocation] = $business_office_menu_id;
        set_theme_mod('nav_menu_locations', $business_office_locations);
    }
  }
     
  // --------Header------------------------

    set_theme_mod( 'business_office_blog_hero_hide', true );
    set_theme_mod( 'business_office_our_services_hide', true );

    set_theme_mod( 'business_office_header_btn_text', 'contact us' ); 
    set_theme_mod( 'business_office_header_btn_url', '#' );
    
    set_theme_mod( 'business_office_our_services_title', 'Our Core Services' );
    set_theme_mod( 'business_office_our_services_left_description', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, ' );

    set_theme_mod( 'business_office_our_services_left_bg_image', get_template_directory_uri() . '/assets/images/services-default.png' );
    
?>