renderLayoutCSS($data); if (!empty($layoutOutput)) { $output .= $layoutOutput . "\n"; } // Custom JS Header $jsHeaderOutput = $this->renderCustomJSHeader($data); if (!empty($jsHeaderOutput)) { $output .= $jsHeaderOutput . "\n"; } return $output; } /** * Genera CSS para el layout configurable * * @param array $data Datos del componente * @return string Bloque style con variables CSS y overrides */ private function renderLayoutCSS(array $data): string { $containerWidth = $data['layout']['container_max_width'] ?? '1320'; // Validar que el valor sea seguro $allowedWidths = ['1140', '1200', '1320', '1400', '100%']; if (!in_array($containerWidth, $allowedWidths, true)) { $containerWidth = '1320'; // Fallback al default } // Generar el CSS $widthValue = ($containerWidth === '100%') ? '100%' : $containerWidth . 'px'; $widthNumeric = ($containerWidth === '100%') ? '100vw' : $containerWidth . 'px'; // Siempre generar CSS variable para que otros componentes puedan usarla $css = sprintf( ' '; return $css; } /** * Genera contenido para wp_footer * * Incluye: * - Custom JS Footer (si configurado) * * @param array $data Datos del componente desde BD * @return string Contenido para wp_footer */ public function renderFooterContent(array $data): string { return $this->renderCustomJSFooter($data); } /** * Genera el JavaScript personalizado para header * * @param array $data Datos del componente * @return string Bloque script o vacio si no hay JS */ private function renderCustomJSHeader(array $data): string { $js = trim($data['custom_code']['custom_js_header'] ?? ''); if (empty($js)) { return ''; } return sprintf( ' ', $js // No escapar JS - usuario avanzado responsable ); } /** * Genera el JavaScript personalizado para footer * * @param array $data Datos del componente * @return string Bloque script o vacio si no hay JS */ private function renderCustomJSFooter(array $data): string { $js = trim($data['custom_code']['custom_js_footer'] ?? ''); if (empty($js)) { return ''; } return sprintf( ' ', $js // No escapar JS - usuario avanzado responsable ); } }