<?php 

/*Remove the editor from home*/
add_action('init', 'remove_editor_Home');
function remove_editor_Home() {
 
    if (isset($_GET['post'])) {
        $post_id = $_GET['post'];
    } else if (isset($_POST['post_ID'])) {
        $post_id = $_POST['post_ID'];
    } else {
        return;
    }
	
    $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
    if ($template_file == 'template-home.php') {
        remove_post_type_support('page', 'editor');
    }
}


add_action( 'init', 'register_posts' );

function register_posts() {

    /*Project Post*/
    register_post_type( 'room_post',
        array(
            'labels' => array(
                'name' => __( "Rooms","um_lang"),
                'singular_name' => __( "Room" ,"um_lang")
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => "room", 'with_front' => TRUE),
            'supports' => array('title','editor','thumbnail','page-attributes')
        )
    );

    /*Project Cateogry*/
    register_taxonomy('room_categories',
        array (0 => 'room_post',),
        array( 'hierarchical' => true, 'label' => __('Room Categories',"um_lang"),'show_ui' => true,'query_var' => true,'singular_label' => __('Room Categories',"um_lang")) );


	/* Add custom categories to the room post */

    	$customCat = get_field('custom_categories', 'options');
        if($customCat){
	        foreach ($customCat as $newCat)
	        {
	            if($newCat["name"] && (preg_replace('/\s+/', '', $newCat["name"]) != '')){
	            $current_cat = "um_".sanitize_text_field(remove_accents(preg_replace('/\s+/', '_', $newCat["name"])));
	            
           	 	register_taxonomy($current_cat,
           	 			array (0 => 'room_post',
				        ),array( 'hierarchical' => true, 
		                'label' => $newCat["name"],'show_ui' => true,'query_var' => true,'singular_label' => $newCat["name"]) );
	            }
	        }
    	}


	/*Service Post*/
    register_post_type( 'service_post',
        array(
            'labels' => array(
                'name' => __( "Services","um_lang"),
                'singular_name' => __( "Services" ,"um_lang")
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => "service", 'with_front' => TRUE),
            'supports' => array('title','editor','thumbnail','page-attributes')
        )
    );
  }
?>