buildHeader($componentId); $html .= '
'; // Columna izquierda - Analytics $html .= '
'; $html .= $this->buildAnalyticsGroup($componentId); $html .= '
'; // Columna derecha - Custom Code $html .= '
'; $html .= $this->buildCustomCodeGroup($componentId); $html .= '
'; $html .= '
'; return $html; } private function buildHeader(string $componentId): string { $html = '
renderer->getFieldValue($componentId, 'analytics', 'ga_tracking_id', ''); $html .= $this->buildTextInput('themeSettingsGaTrackingId', 'Google Analytics ID', 'bi-bar-chart', $gaTrackingId); $html .= '
Formato: G-XXXXXXXXXX o UA-XXXXXXXX-X
'; $gaAnonymizeIp = $this->renderer->getFieldValue($componentId, 'analytics', 'ga_anonymize_ip', true); $html .= $this->buildSwitch('themeSettingsGaAnonymizeIp', 'Anonimizar IP (GDPR)', 'bi-shield-check', $gaAnonymizeIp); $html .= '
'; $html .= ' '; $html .= ' Recomendado activar para cumplir con GDPR/RGPD'; $html .= '
'; $html .= '
'; $html .= ''; return $html; } private function buildCustomCodeGroup(string $componentId): string { $html = '
'; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' Codigo Personalizado'; $html .= '
'; $customCss = $this->renderer->getFieldValue($componentId, 'custom_code', 'custom_css', ''); $html .= $this->buildTextareaCode('themeSettingsCustomCss', 'CSS Personalizado', 'bi-filetype-css', $customCss, 'Se inyecta en wp_head. No incluir etiquetas <style>'); $customJsHeader = $this->renderer->getFieldValue($componentId, 'custom_code', 'custom_js_header', ''); $html .= $this->buildTextareaCode('themeSettingsCustomJsHeader', 'JavaScript en Header', 'bi-filetype-js', $customJsHeader, 'Se inyecta en wp_head. No incluir etiquetas <script>'); $customJsFooter = $this->renderer->getFieldValue($componentId, 'custom_code', 'custom_js_footer', ''); $html .= $this->buildTextareaCode('themeSettingsCustomJsFooter', 'JavaScript en Footer', 'bi-filetype-js', $customJsFooter, 'Se inyecta en wp_footer. No incluir etiquetas <script>'); $html .= '
'; $html .= ' '; $html .= ' Advertencia: El codigo personalizado puede afectar el rendimiento y seguridad del sitio.'; $html .= '
'; $html .= '
'; $html .= '
'; return $html; } // Helper methods private function buildSwitch(string $id, string $label, string $icon, $value): string { $checked = $value === true || $value === '1' || $value === 1 ? 'checked' : ''; $html = '
'; $html .= ' '; $html .= ' '; $html .= '
'; return $html; } private function buildTextInput(string $id, string $label, string $icon, mixed $value): string { $value = $this->normalizeStringValue($value); $html = '
'; $html .= ' '; $html .= ' '; $html .= '
'; return $html; } private function buildTextareaCode(string $id, string $label, string $icon, mixed $value, string $helpText = ''): string { $value = $this->normalizeStringValue($value); $html = '
'; $html .= ' '; $html .= ' '; if (!empty($helpText)) { $html .= '
' . $helpText . '
'; } $html .= '
'; return $html; } /** * Normaliza un valor a string para inputs de formulario */ private function normalizeStringValue(mixed $value): string { if ($value === false) { return '0'; } if ($value === true) { return '1'; } return (string) $value; } }