Remodulación del Top Bar siguiendo algoritmo v2.1 actualizado.
## 1. Valores de Estilos desde CSS
**Antes (v2.0):**
```php
'custom_styles' => array(
'background_color' => '', // Vacío
'text_color' => '', // Vacío
'highlight_color' => '', // Vacío
'link_hover_color' => '', // Vacío
)
```
**Ahora (v2.1):**
```php
'custom_styles' => array(
'background_color' => '#0E2337', // Extraído de componente-top-bar.css
'text_color' => '#ffffff',
'highlight_color' => '#FF8600', // var(--color-orange-primary)
'link_hover_color' => '#FF8600',
'font_size' => 'normal' // 0.9rem del CSS
)
```
**Mapping CSS → Defaults:**
- `.top-notification-bar { background-color: var(--color-navy-dark) }` → `#0E2337`
- `.top-notification-bar { color: #ffffff }` → `#ffffff`
- `.top-notification-bar strong { color: var(--color-orange-primary) }` → `#FF8600`
- `.top-notification-bar a:hover { color: var(--color-orange-primary) }` → `#FF8600`
## 2. UI Compacta
**Antes:** Checkboxes dispersos (cada uno fila completa)
**Ahora:**
- Checkboxes móvil/desktop → Fila de 2 columnas (col-md-6)
- Campos enlace (texto + URL + target) → Fila compacta (col-md-5 + 5 + 2)
- Colores ya estaban bien (row con col-md-3)
**Resultado:** Menos scroll, mejor aprovechamiento del espacio.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
185 lines
5.0 KiB
PHP
185 lines
5.0 KiB
PHP
<?php
|
|
/**
|
|
* Settings Manager Class
|
|
*
|
|
* CRUD de configuraciones por componentes
|
|
*
|
|
* @package Apus_Theme
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class APUS_Settings_Manager {
|
|
|
|
const OPTION_NAME = 'apus_theme_settings';
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('wp_ajax_apus_get_settings', array($this, 'ajax_get_settings'));
|
|
add_action('wp_ajax_apus_save_settings', array($this, 'ajax_save_settings'));
|
|
}
|
|
|
|
/**
|
|
* Obtener configuraciones
|
|
*/
|
|
public function get_settings() {
|
|
$settings = get_option(self::OPTION_NAME, array());
|
|
$defaults = $this->get_defaults();
|
|
|
|
return wp_parse_args($settings, $defaults);
|
|
}
|
|
|
|
/**
|
|
* Guardar configuraciones
|
|
*/
|
|
public function save_settings($data) {
|
|
// Validar
|
|
$validator = new APUS_Validator();
|
|
$validation = $validator->validate($data);
|
|
|
|
if (!$validation['valid']) {
|
|
return array(
|
|
'success' => false,
|
|
'message' => 'Error de validación',
|
|
'errors' => $validation['errors']
|
|
);
|
|
}
|
|
|
|
// Sanitizar
|
|
$sanitized = $this->sanitize_settings($data);
|
|
|
|
// Agregar metadata
|
|
$sanitized['version'] = APUS_ADMIN_PANEL_VERSION;
|
|
$sanitized['updated_at'] = current_time('mysql');
|
|
|
|
// Guardar
|
|
update_option(self::OPTION_NAME, $sanitized, false);
|
|
|
|
return array(
|
|
'success' => true,
|
|
'message' => 'Configuración guardada correctamente'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Valores por defecto
|
|
* NOTA: Aquí se agregan los defaults de cada componente
|
|
*/
|
|
public function get_defaults() {
|
|
return array(
|
|
'version' => APUS_ADMIN_PANEL_VERSION,
|
|
'components' => array(
|
|
'top_bar' => array(
|
|
'enabled' => true,
|
|
'show_on_mobile' => true,
|
|
'show_on_desktop' => true,
|
|
'icon_class' => 'bi bi-megaphone-fill',
|
|
'show_icon' => true,
|
|
'highlight_text' => 'Nuevo:',
|
|
'message_text' => 'Accede a más de 200,000 Análisis de Precios Unitarios actualizados para 2025.',
|
|
'link_text' => 'Ver Catálogo',
|
|
'link_url' => '/catalogo',
|
|
'link_target' => '_self',
|
|
'show_link' => true,
|
|
'custom_styles' => array(
|
|
// Valores extraídos de componente-top-bar.css
|
|
'background_color' => '#0E2337', // var(--color-navy-dark)
|
|
'text_color' => '#ffffff',
|
|
'highlight_color' => '#FF8600', // var(--color-orange-primary)
|
|
'link_hover_color' => '#FF8600', // var(--color-orange-primary)
|
|
'font_size' => 'normal' // 0.9rem del CSS
|
|
)
|
|
)
|
|
// Navbar - Pendiente
|
|
// Hero - Pendiente
|
|
// Footer - Pendiente
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Sanitizar configuraciones
|
|
* NOTA: Aquí se agrega sanitización de cada componente
|
|
*/
|
|
public function sanitize_settings($data) {
|
|
$sanitized = array(
|
|
'components' => array()
|
|
);
|
|
|
|
// Sanitizar Top Bar
|
|
if (isset($data['components']['top_bar'])) {
|
|
$top_bar = $data['components']['top_bar'];
|
|
|
|
$sanitized['components']['top_bar'] = array(
|
|
'enabled' => !empty($top_bar['enabled']),
|
|
'show_on_mobile' => !empty($top_bar['show_on_mobile']),
|
|
'show_on_desktop' => !empty($top_bar['show_on_desktop']),
|
|
'icon_class' => sanitize_text_field($top_bar['icon_class'] ?? ''),
|
|
'show_icon' => !empty($top_bar['show_icon']),
|
|
'highlight_text' => sanitize_text_field($top_bar['highlight_text'] ?? ''),
|
|
'message_text' => sanitize_text_field($top_bar['message_text'] ?? ''),
|
|
'link_text' => sanitize_text_field($top_bar['link_text'] ?? ''),
|
|
'link_url' => esc_url_raw($top_bar['link_url'] ?? ''),
|
|
'link_target' => in_array($top_bar['link_target'] ?? '', array('_self', '_blank')) ? $top_bar['link_target'] : '_self',
|
|
'show_link' => !empty($top_bar['show_link']),
|
|
'custom_styles' => array(
|
|
'background_color' => sanitize_hex_color($top_bar['custom_styles']['background_color'] ?? ''),
|
|
'text_color' => sanitize_hex_color($top_bar['custom_styles']['text_color'] ?? ''),
|
|
'highlight_color' => sanitize_hex_color($top_bar['custom_styles']['highlight_color'] ?? ''),
|
|
'link_hover_color' => sanitize_hex_color($top_bar['custom_styles']['link_hover_color'] ?? ''),
|
|
'font_size' => in_array($top_bar['custom_styles']['font_size'] ?? '', array('small', 'normal', 'large')) ? $top_bar['custom_styles']['font_size'] : 'normal'
|
|
)
|
|
);
|
|
}
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* AJAX: Obtener configuraciones
|
|
*/
|
|
public function ajax_get_settings() {
|
|
check_ajax_referer('apus_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Permisos insuficientes');
|
|
}
|
|
|
|
$settings = $this->get_settings();
|
|
wp_send_json_success($settings);
|
|
}
|
|
|
|
/**
|
|
* AJAX: Guardar configuraciones
|
|
*/
|
|
public function ajax_save_settings() {
|
|
check_ajax_referer('apus_admin_nonce', 'nonce');
|
|
|
|
if (!current_user_can('manage_options')) {
|
|
wp_send_json_error('Permisos insuficientes');
|
|
}
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if (!$data) {
|
|
wp_send_json_error('Datos inválidos');
|
|
}
|
|
|
|
$result = $this->save_settings($data);
|
|
|
|
if ($result['success']) {
|
|
wp_send_json_success($result);
|
|
} else {
|
|
wp_send_json_error($result);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Instanciar clase
|
|
new APUS_Settings_Manager();
|