> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokkoplugins.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Opciones de WordPress

> Todas las opciones (wp_options) utilizadas por el plugin

# Opciones de WordPress

El plugin Tokko almacena todas sus configuraciones en las opciones de WordPress (`wp_options`). Esta referencia documentan todas las opciones disponibles, sus valores, tipos y cómo accederlas.

## Configuración de API

Estas opciones contienen los detalles de conexión con Tokko Broker.

### thi\_api\_key

Clave de autenticación para la API de Tokko Broker.

<CodeGroup>
  ```php Obtener theme={null}
  $api_key = get_option('thi_api_key');
  ```

  ```php Establecer theme={null}
  update_option('thi_api_key', 'tu-clave-api-aqui');
  ```
</CodeGroup>

| Propiedad                | Valor                                                                               |
| ------------------------ | ----------------------------------------------------------------------------------- |
| **Tipo**                 | string                                                                              |
| **Valor predeterminado** | '' (vacío)                                                                          |
| **Requerido**            | Sí                                                                                  |
| **Sensible**             | Sí - No mostrar en formularios públicos                                             |
| **Descripción**          | Clave de autenticación de TokkoBroker API. Se obtiene en panel de control de Tokko. |

<Warning>
  Esta es una clave sensible. No la expongas en código público o repositorios Git.
</Warning>

***

### thi\_language

Idioma usado al consumir la API de Tokko Broker. Afecta principalmente a cómo se muestran campos localizables que entrega Tokko (ej. nombres de operaciones).

<CodeGroup>
  ```php Obtener theme={null}
  $language = get_option('thi_language', 'es_ar');
  ```

  ```php Establecer theme={null}
  update_option('thi_language', 'es_ar');
  ```
</CodeGroup>

| Propiedad                | Valor                                         |
| ------------------------ | --------------------------------------------- |
| **Tipo**                 | string                                        |
| **Valor predeterminado** | `'es_ar'`                                     |
| **Descripción**          | Locale que se envía a la API de Tokko Broker. |

***

### thi\_plugin\_language

Idioma de la interfaz administrativa del plugin (menús, tabs, mensajes).

<CodeGroup>
  ```php Obtener theme={null}
  $lang = get_option('thi_plugin_language', 'en_US');
  ```

  ```php Establecer theme={null}
  update_option('thi_plugin_language', 'es_MX');
  ```
</CodeGroup>

| Propiedad                | Valor                                                                          |
| ------------------------ | ------------------------------------------------------------------------------ |
| **Tipo**                 | string                                                                         |
| **Valor predeterminado** | `'en_US'` (desde la UI de configuración)                                       |
| **Valores válidos**      | `'en_US'`, `'es_MX'`                                                           |
| **Descripción**          | Locale para traducción del panel del plugin (no afecta el frontend de Houzez). |

***

## Configuración de sincronización

### thi\_sync\_option

Tipo de sincronización configurado.

<CodeGroup>
  ```php Obtener theme={null}
  $sync_type = get_option('thi_sync_option', 'daily');
  ```

  ```php Establecer theme={null}
  update_option('thi_sync_option', 'hourly');
  ```
</CodeGroup>

| Propiedad                | Valor                                                                                                                                    |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **Tipo**                 | string                                                                                                                                   |
| **Valor predeterminado** | `'daily'`                                                                                                                                |
| **Valores válidos**      | `'disabled'`, `'hourly'`, `'every_6_hours'`, `'every_12_hours'`, `'daily'`, `'weekly'`, `'biweekly'`, `'monthly'`, `'custom'`            |
| **Descripción**          | Frecuencia de sincronización automática (feature premium). En plan Starter permanece en `disabled` y sólo soporta sincronización manual. |

***

### thi\_custom\_interval\_value

Valor personalizado en minutos para sincronización custom.

<CodeGroup>
  ```php Obtener theme={null}
  $interval = get_option('thi_custom_interval_value', 60);
  ```

  ```php Establecer theme={null}
  update_option('thi_custom_interval_value', 120);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                                                                     |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
| **Tipo**                 | int                                                                                                                       |
| **Valor predeterminado** | `60`                                                                                                                      |
| **Rango válido**         | 5 – 43200 (minutos)                                                                                                       |
| **Unidad**               | Minutos                                                                                                                   |
| **Descripción**          | Se usa solo cuando `thi_sync_option` es `'custom'`. Va desde 5 minutos (máxima frecuencia) hasta 30 días (43200 minutos). |

***

### thi\_sync\_developments

Habilita sincronización de desarrollos.

<CodeGroup>
  ```php Obtener theme={null}
  $sync_devs = get_option('thi_sync_developments', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_sync_developments', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                     |
| ------------------------ | ------------------------------------------------------------------------- |
| **Tipo**                 | bool                                                                      |
| **Valor predeterminado** | false                                                                     |
| **Descrición**           | Si está habilitado, también sincroniza desarrollos además de propiedades. |

***

## Configuración de visualización

### thi\_default\_map\_enabled

Muestra mapa por defecto en páginas de propiedad.

<CodeGroup>
  ```php Obtener theme={null}
  $map_enabled = get_option('thi_default_map_enabled', true);
  ```

  ```php Establecer theme={null}
  update_option('thi_default_map_enabled', false);
  ```
</CodeGroup>

| Propiedad                | Valor                                                           |
| ------------------------ | --------------------------------------------------------------- |
| **Tipo**                 | bool                                                            |
| **Valor predeterminado** | true                                                            |
| **Descripción**          | Controla si los mapas de ubicación se muestran automáticamente. |

***

### thi\_generate\_thumbnails

Genera miniaturas de imágenes al sincronizar.

<CodeGroup>
  ```php Obtener theme={null}
  $thumbnails = get_option('thi_generate_thumbnails', true);
  ```

  ```php Establecer theme={null}
  update_option('thi_generate_thumbnails', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                               |
| ------------------------ | ------------------------------------------------------------------- |
| **Tipo**                 | bool                                                                |
| **Valor predeterminado** | true                                                                |
| **Descripción**          | Si está activo, crea miniaturas de imágenes para mejor rendimiento. |

***

### thi\_enable\_secondary\_url

Habilita URL secundaria para propiedades.

<CodeGroup>
  ```php Obtener theme={null}
  $secondary = get_option('thi_enable_secondary_url', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_enable_secondary_url', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                       |
| ------------------------ | ------------------------------------------- |
| **Tipo**                 | bool                                        |
| **Valor predeterminado** | false                                       |
| **Descripción**          | Permite URLs alternativas para propiedades. |

***

### thi\_enable\_tokko\_broker\_url

Enlaza a Tokko Broker en lugar de mostrar en sitio.

<CodeGroup>
  ```php Obtener theme={null}
  $tokko_url = get_option('thi_enable_tokko_broker_url', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_enable_tokko_broker_url', false);
  ```
</CodeGroup>

| Propiedad                | Valor                                                     |
| ------------------------ | --------------------------------------------------------- |
| **Tipo**                 | bool                                                      |
| **Valor predeterminado** | false                                                     |
| **Descripción**          | Si está activo, las propiedades redirigen a Tokko Broker. |

***

### thi\_use\_address\_as\_title

Usa dirección como título de propiedad.

<CodeGroup>
  ```php Obtener theme={null}
  $address_title = get_option('thi_use_address_as_title', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_use_address_as_title', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                 |
| ------------------------ | --------------------------------------------------------------------- |
| **Tipo**                 | bool                                                                  |
| **Valor predeterminado** | false                                                                 |
| **Descripción**          | Si está habilitado, las direcciones se usan como títulos principales. |

***

### thi\_hide\_property\_address

Oculta la dirección completa de propiedades.

<CodeGroup>
  ```php Obtener theme={null}
  $hide_address = get_option('thi_hide_property_address', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_hide_property_address', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                        |
| ------------------------ | -------------------------------------------- |
| **Tipo**                 | bool                                         |
| **Valor predeterminado** | false                                        |
| **Descripción**          | Oculta la dirección completa por privacidad. |

***

## Configuración de búsqueda avanzada

### thi\_enhanced\_search\_enabled

Activa búsqueda mejorada de propiedades.

<CodeGroup>
  ```php Obtener theme={null}
  $search_enabled = get_option('thi_enhanced_search_enabled', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_enhanced_search_enabled', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                |
| ------------------------ | ---------------------------------------------------- |
| **Tipo**                 | bool                                                 |
| **Valor predeterminado** | false                                                |
| **Descripción**          | Habilita filtros avanzados y búsqueda personalizada. |

***

### thi\_enhanced\_search\_fields

Campos habilitados para búsqueda avanzada.

<CodeGroup>
  ```php Obtener theme={null}
  $fields = get_option('thi_enhanced_search_fields', []);
  ```

  ```php Establecer theme={null}
  update_option('thi_enhanced_search_fields', [
      'precio',
      'dormitorios',
      'baños',
      'área',
      'tipo_propiedad'
  ]);
  ```
</CodeGroup>

| Propiedad                | Valor                                             |
| ------------------------ | ------------------------------------------------- |
| **Tipo**                 | array                                             |
| **Valor predeterminado** | \[] (vacío)                                       |
| **Descripción**          | Lista de campos disponibles en búsqueda avanzada. |

***

### thi\_age\_range\_slider\_color

Color personalizado del control deslizante "Edad de la propiedad".

<CodeGroup>
  ```php Obtener theme={null}
  $color = get_option('thi_age_range_slider_color', '');
  ```

  ```php Establecer theme={null}
  update_option('thi_age_range_slider_color', '#e74c3c');
  ```
</CodeGroup>

| Propiedad                | Valor                                                                                         |
| ------------------------ | --------------------------------------------------------------------------------------------- |
| **Tipo**                 | string                                                                                        |
| **Valor predeterminado** | `''` (sin override; usa el color del tema)                                                    |
| **Formato**              | Código hexadecimal de color (ej. `'#007bff'`)                                                 |
| **Descripción**          | Color personalizado del slider de edad; si queda vacío, se usa el color por defecto del tema. |

***

### thi\_age\_range\_slider\_label

Etiqueta del slider de edad de la propiedad.

<CodeGroup>
  ```php Obtener theme={null}
  $label = get_option('thi_age_range_slider_label', 'Edad de la propiedad');
  ```

  ```php Establecer theme={null}
  update_option('thi_age_range_slider_label', 'Antigüedad');
  ```
</CodeGroup>

| Propiedad                | Valor                                                            |
| ------------------------ | ---------------------------------------------------------------- |
| **Tipo**                 | string                                                           |
| **Valor predeterminado** | `'Edad de la propiedad'`                                         |
| **Descripción**          | Etiqueta visible encima del slider en el formulario de búsqueda. |

***

### thi\_age\_range\_slider\_half\_map\_enabled

Muestra slider a mitad de mapa.

<CodeGroup>
  ```php Obtener theme={null}
  $half_map = get_option('thi_age_range_slider_half_map_enabled', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_age_range_slider_half_map_enabled', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                    |
| ------------------------ | -------------------------------------------------------- |
| **Tipo**                 | bool                                                     |
| **Valor predeterminado** | false                                                    |
| **Descripción**          | Posiciona el slider al lado del mapa en lugar de arriba. |

***

## Configuración de agentes

### thi\_enable\_agent\_sync

Habilita sincronización de agentes desde Tokko.

<CodeGroup>
  ```php Obtener theme={null}
  $agent_sync = get_option('thi_enable_agent_sync', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_enable_agent_sync', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                |
| ------------------------ | -------------------------------------------------------------------- |
| **Tipo**                 | bool                                                                 |
| **Valor predeterminado** | false                                                                |
| **Descripción**          | Si está activo, sincroniza agentes de Tokko como posts en WordPress. |

***

### thi\_agent\_mobile\_is\_whatsapp

Trata números móviles de agentes como WhatsApp.

<CodeGroup>
  ```php Obtener theme={null}
  $whatsapp = get_option('thi_agent_mobile_is_whatsapp', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_agent_mobile_is_whatsapp', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                            |
| ------------------------ | ------------------------------------------------ |
| **Tipo**                 | bool                                             |
| **Valor predeterminado** | false                                            |
| **Descripción**          | Convierte números móviles a enlaces de WhatsApp. |

***

### thi\_download\_agent\_images

Descarga imágenes de agentes localmente.

<CodeGroup>
  ```php Obtener theme={null}
  $download_imgs = get_option('thi_download_agent_images', true);
  ```

  ```php Establecer theme={null}
  update_option('thi_download_agent_images', false);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                       |
| ------------------------ | --------------------------------------------------------------------------- |
| **Tipo**                 | bool                                                                        |
| **Valor predeterminado** | true                                                                        |
| **Descripción**          | Si está habilitado, descarga y almacena imágenes de agentes en el servidor. |

***

### thi\_auto\_assign\_agent\_id

ID de agente para asignación automática de propiedades.

<CodeGroup>
  ```php Obtener theme={null}
  $agent_id = get_option('thi_auto_assign_agent_id', 0);
  ```

  ```php Establecer theme={null}
  update_option('thi_auto_assign_agent_id', 123);
  ```
</CodeGroup>

| Propiedad                | Valor                                                                  |
| ------------------------ | ---------------------------------------------------------------------- |
| **Tipo**                 | int                                                                    |
| **Valor predeterminado** | 0 (ninguno)                                                            |
| **Descripción**          | ID de WordPress del agente que recibe propiedades sin agente asignado. |

***

## Configuración de imágenes

### thi\_image\_quality

Perfil de calidad usado para descargar imágenes de propiedades.

<CodeGroup>
  ```php Obtener theme={null}
  $quality = get_option('thi_image_quality', 'optimized');
  ```

  ```php Establecer theme={null}
  update_option('thi_image_quality', 'original');
  ```
</CodeGroup>

| Propiedad                | Valor                                                                                                                                |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| **Tipo**                 | string                                                                                                                               |
| **Valor predeterminado** | `'optimized'`                                                                                                                        |
| **Descripción**          | Controla qué variante de la imagen se baja desde Tokko. Valores soportados por la API típicamente incluyen `original` y `optimized`. |
| **Impacto**              | Afecta directamente el tamaño de disco y la velocidad de carga del frontend.                                                         |

***

## Configuración de contacto

### thi\_enable\_contact\_integration

Habilita integración de formularios de contacto.

<CodeGroup>
  ```php Obtener theme={null}
  $contact_enabled = get_option('thi_enable_contact_integration', false);
  ```

  ```php Establecer theme={null}
  update_option('thi_enable_contact_integration', true);
  ```
</CodeGroup>

| Propiedad                | Valor                                                            |
| ------------------------ | ---------------------------------------------------------------- |
| **Tipo**                 | bool                                                             |
| **Valor predeterminado** | false                                                            |
| **Descripción**          | Si está activo, conecta formularios de contacto con Tokko y CRM. |

***

## Notificaciones por email

<Note>
  Las notificaciones por email son una característica **premium** (Professional / Pro+). En el plan Starter el filtro [`thi_notifications_enabled`](/api-reference/filtros#thi-notifications-enabled) las desactiva por defecto.
</Note>

### thi\_email\_error\_alert\_enabled

Habilita el envío de alertas por email cuando el plugin registra errores.

<CodeGroup>
  ```php Obtener theme={null}
  $enabled = get_option('thi_email_error_alert_enabled', 'yes');
  ```

  ```php Establecer theme={null}
  update_option('thi_email_error_alert_enabled', 'no');
  ```
</CodeGroup>

| Propiedad                | Valor                                      |
| ------------------------ | ------------------------------------------ |
| **Tipo**                 | string (`'yes'` / `'no'`)                  |
| **Valor predeterminado** | `'yes'`                                    |
| **Descripción**          | Conmutador principal de alertas por email. |

***

### thi\_email\_error\_alert\_level

Nivel mínimo de severidad para disparar una alerta por email.

<CodeGroup>
  ```php Obtener theme={null}
  $level = get_option('thi_email_error_alert_level', 'critical');
  ```

  ```php Establecer theme={null}
  update_option('thi_email_error_alert_level', 'warning');
  ```
</CodeGroup>

| Propiedad                | Valor                                                              |
| ------------------------ | ------------------------------------------------------------------ |
| **Tipo**                 | string                                                             |
| **Valor predeterminado** | `'critical'`                                                       |
| **Valores típicos**      | `'warning'`, `'error'`, `'critical'`                               |
| **Descripción**          | Solo los errores iguales o superiores a este nivel disparan email. |

***

### thi\_email\_error\_alert\_recipients

Destinatarios de las alertas de error (uno o varios, separados por comas o saltos de línea).

<CodeGroup>
  ```php Obtener theme={null}
  $recipients = get_option('thi_email_error_alert_recipients', '');
  ```

  ```php Establecer theme={null}
  update_option('thi_email_error_alert_recipients', "admin@example.com\nops@example.com");
  ```
</CodeGroup>

| Propiedad                | Valor                                         |
| ------------------------ | --------------------------------------------- |
| **Tipo**                 | string                                        |
| **Valor predeterminado** | `''` (vacío)                                  |
| **Formato**              | Una dirección por línea o separadas por coma. |

***

### thi\_email\_periodic\_enabled

Habilita el reporte periódico por email (resumen de sincronización).

<CodeGroup>
  ```php Obtener theme={null}
  $enabled = get_option('thi_email_periodic_enabled', 'no');
  ```

  ```php Establecer theme={null}
  update_option('thi_email_periodic_enabled', 'yes');
  ```
</CodeGroup>

| Propiedad                | Valor                     |
| ------------------------ | ------------------------- |
| **Tipo**                 | string (`'yes'` / `'no'`) |
| **Valor predeterminado** | `'no'`                    |

***

### thi\_email\_periodic\_frequency

Frecuencia del reporte periódico.

<CodeGroup>
  ```php Obtener theme={null}
  $frequency = get_option('thi_email_periodic_frequency', 'weekly');
  ```
</CodeGroup>

| Propiedad                | Valor                              |
| ------------------------ | ---------------------------------- |
| **Tipo**                 | string                             |
| **Valor predeterminado** | `'weekly'`                         |
| **Valores válidos**      | `'daily'`, `'weekly'`, `'monthly'` |

***

### thi\_email\_periodic\_recipients

Destinatarios del reporte periódico (mismo formato que las alertas).

<CodeGroup>
  ```php Obtener theme={null}
  $recipients = get_option('thi_email_periodic_recipients', '');
  ```
</CodeGroup>

| Propiedad                | Valor  |
| ------------------------ | ------ |
| **Tipo**                 | string |
| **Valor predeterminado** | `''`   |

***

### thi\_email\_from\_name

Nombre que aparece como remitente en los emails enviados por el plugin.

<CodeGroup>
  ```php Obtener theme={null}
  $from_name = get_option('thi_email_from_name', '');
  ```

  ```php Establecer theme={null}
  update_option('thi_email_from_name', 'Inmobiliaria Ejemplo');
  ```
</CodeGroup>

| Propiedad                | Valor                              |
| ------------------------ | ---------------------------------- |
| **Tipo**                 | string                             |
| **Valor predeterminado** | `''` (usa el default de WordPress) |

***

## Estado y rastreo

Estas opciones son actualizadas automáticamente por el plugin y generalmente no deben modificarse manualmente.

### thi\_last\_sync\_time

Timestamp de la última sincronización completada.

<CodeGroup>
  ```php Obtener theme={null}
  $last_sync = get_option('thi_last_sync_time', null);
  ```

  ```php Solo lectura theme={null}
  // Esta opción se actualiza automáticamente
  ```
</CodeGroup>

| Propiedad                | Valor                                                               |
| ------------------------ | ------------------------------------------------------------------- |
| **Tipo**                 | string (ISO 8601)                                                   |
| **Valor predeterminado** | null                                                                |
| **Descripción**          | Registro automático de cuándo se completó la última sincronización. |

***

### thi\_last\_sync\_metadata

Información detallada de la última sincronización.

<CodeGroup>
  ```php Obtener theme={null}
  $metadata = get_option('thi_last_sync_metadata', []);

  // Estructura típica:
  echo $metadata['properties_created']; // int
  echo $metadata['properties_updated']; // int
  echo $metadata['images_processed'];    // int
  echo $metadata['duration'];            // float (segundos)
  echo $metadata['status'];              // 'success', 'error', 'warning'
  ```
</CodeGroup>

| Propiedad       | Valor                                                                            |
| --------------- | -------------------------------------------------------------------------------- |
| **Tipo**        | array                                                                            |
| **Estructura**  | Array con claves: created, updated, deleted, images\_processed, duration, status |
| **Descripción** | Metadatos detallados de la última sincronización.                                |

***

### thi\_recent\_sync\_results

Historial de últimas sincronizaciones (máximo 10).

<CodeGroup>
  ```php Obtener theme={null}
  $results = get_option('thi_recent_sync_results', []);

  foreach ($results as $sync) {
      echo $sync['timestamp'] . ': ' . $sync['status'];
  }
  ```
</CodeGroup>

| Propiedad       | Valor                                                        |
| --------------- | ------------------------------------------------------------ |
| **Tipo**        | array                                                        |
| **Descripción** | Array de objetos con resultados de últimas sincronizaciones. |

***

### thi\_sync\_error\_history

Historial de errores de sincronización.

<CodeGroup>
  ```php Obtener theme={null}
  $errors = get_option('thi_sync_error_history', []);

  foreach ($errors as $error) {
      echo 'Fecha: ' . $error['timestamp'];
      echo 'Error: ' . $error['message'];
      echo 'Código: ' . $error['code'];
  }
  ```
</CodeGroup>

| Propiedad       | Valor                                              |
| --------------- | -------------------------------------------------- |
| **Tipo**        | array                                              |
| **Descripción** | Lista de errores ocurridos durante sincronización. |
| **Retención**   | Últimos 50 errores                                 |

***

### thi\_plugin\_version

Versión actual del plugin instalado.

<CodeGroup>
  ```php Obtener theme={null}
  $version = get_option('thi_plugin_version', '1.0.0');
  ```
</CodeGroup>

| Propiedad       | Valor                                                           |
| --------------- | --------------------------------------------------------------- |
| **Tipo**        | string                                                          |
| **Descripción** | Versión del plugin. Se actualiza automáticamente al actualizar. |

***

### thi\_last\_api\_connection

Timestamp del último contacto exitoso con API.

<CodeGroup>
  ```php Obtener theme={null}
  $last_api = get_option('thi_last_api_connection', null);
  ```
</CodeGroup>

| Propiedad       | Valor                                                 |
| --------------- | ----------------------------------------------------- |
| **Tipo**        | string (ISO 8601)                                     |
| **Descripción** | Ayuda a detectar problemas de conectividad con Tokko. |

***

### thi\_last\_api\_response\_time

Tiempo de respuesta (en ms) de la última llamada API.

<CodeGroup>
  ```php Obtener theme={null}
  $response_time = get_option('thi_last_api_response_time', 0);

  echo 'Última respuesta: ' . $response_time . 'ms';
  ```
</CodeGroup>

| Propiedad       | Valor                                                   |
| --------------- | ------------------------------------------------------- |
| **Tipo**        | int                                                     |
| **Unidad**      | Milisegundos                                            |
| **Descripción** | Útil para monitorear rendimiento de conexión con Tokko. |

***

## Acceso a opciones en código

### Obtener opciones

```php theme={null}
// Obtener con valor predeterminado
$api_key = get_option('thi_api_key', 'default_value');

// Obtener sin valor predeterminado
$api_key = get_option('thi_api_key');

// Obtener y decodificar JSON
$fields = json_decode(get_option('thi_enhanced_search_fields', '[]'), true);
```

### Actualizar opciones

```php theme={null}
// Actualizar simple
update_option('thi_api_key', 'nueva-clave');

// Actualizar con serialización automática
update_option('thi_enhanced_search_fields', [
    'precio',
    'dormitorios'
]);

// Usar add_option si es nueva
add_option('thi_custom_option', 'valor', '', 'yes');
```

### Eliminar opciones

```php theme={null}
// Eliminar opción
delete_option('thi_custom_option');
```

***

## Mejores prácticas

<Note>
  **No edites directamente en la base de datos.** Siempre usa funciones de WordPress para garantizar sanitización y validación correctas.
</Note>

<Tip>
  **Usa nombres con prefijo** al crear opciones personalizadas para evitar conflictos:

  ```php theme={null}
  // ✅ CORRECTO
  add_option('thi_my_custom_option', $value);

  // ❌ INCORRECTO
  add_option('custom_option', $value);
  ```
</Tip>

```php theme={null}
// ✅ BUEN EJEMPLO - Actualizar opción con validación
function update_my_option($value) {
    // Validar
    if (!is_array($value)) {
        return false;
    }

    // Sanitizar
    $sanitized = array_map('sanitize_text_field', $value);

    // Actualizar
    return update_option('thi_my_option', $sanitized);
}
```

***

## Exportar/Importar opciones

```php theme={null}
// Exportar todas las opciones de Tokko
$tokko_options = [];
$all_options = wp_load_alloptions();

foreach ($all_options as $name => $value) {
    if (strpos($name, 'thi_') === 0) {
        $tokko_options[$name] = $value;
    }
}

echo json_encode($tokko_options);

// Importar opciones
$backup = json_decode(file_get_contents('backup.json'), true);

foreach ($backup as $name => $value) {
    update_option($name, $value);
}
```
