/*
	Theme Name: Real Places
	Theme URI: http://themeforest.net/item/real-places-responsive-wordpress-real-estate-theme/12579089
	Description: A purpose oriented WordPress theme for Real Estate Websites.
	Author: Inspiry Themes
	Author URI: http://themeforest.net/user/inspirythemes/portfolio
	Version: 1.9.10
	Text Domain: inspiry
    Domain Path: /languages
	License: GNU General Public License version 3.0
	License URI: http://www.gnu.org/licenses/gpl-3.0.html
	Tags: custom-background, threaded-comments, translation-ready, one-column, two-columns, three-columns, four-columns, custom-menu, theme-options, left-sidebar, right-sidebar, featured-images, full-width-template, threaded-comments, post-formats, rtl-language-support, custom-colors


	----------------------------------------------------------------------------------------------------------------*/
/* ============================================================
   VIP EXPATS: MCP SERVER AUTOMATION UNLOCKER
   Permite automatizar Propiedades, Taxonomías y Precios vía REST API
   ============================================================ */
add_action('init', function() {
    global $wp_post_types, $wp_taxonomies;
    
    // 1. Desbloquear el inventario principal (Custom Post Type 'property')
    if (isset($wp_post_types['property'])) {
        $wp_post_types['property']->show_in_rest = true;
    }
    
    // 2. Desbloquear Filtros y Categorías (Locaciones, Estados, Tipos, Características)
    $taxonomias = ['property-city', 'property-status', 'property-type', 'property-feature'];
    foreach ($taxonomias as $tax) {
        if (isset($wp_taxonomies[$tax])) {
            $wp_taxonomies[$tax]->show_in_rest = true;
        }
    }
}, 999);

// 3. Desbloquear la escritura automatizada de Precios y Detalles (Post Meta)
add_action('rest_api_init', function() {
    register_rest_field('property', 'mcp_meta', array(
        'get_callback'    => function($post) { return get_post_meta($post['id']); },
        'update_callback' => function($meta_data, $post) {
            if (is_array($meta_data)) {
                foreach ($meta_data as $key => $value) {
                    update_post_meta($post->ID, $key, $value);
                }
            }
            return true;
        }
    ));
});
