fix(wrappers): eliminar wrappers vacíos y corregir exclusiones AdSense (Plan 99.15)
## Problema - Componentes deshabilitados/excluidos dejaban wrappers HTML vacíos (navbar 32px, sidebar col-lg-3 294px) - AdSense ignoraba exclusiones por URL pattern en grupo _exclusions ## Solución Plan 99.15 (Clean Architecture) ### Domain Layer - WrapperVisibilityCheckerInterface: contrato para verificar visibilidad ### Application Layer - CheckWrapperVisibilityUseCase: orquesta verificaciones de visibilidad ### Infrastructure Layer - WordPressComponentVisibilityRepository: consulta BD + PageVisibilityHelper - WrapperVisibilityService: facade estático para templates - BodyClassHooksRegistrar: agrega clases CSS failsafe al body ### Templates modificados - header.php: renderizado condicional de <nav> wrapper - page.php/single.php: lógica dinámica col-lg-9/col-lg-12 según sidebar ### CSS Failsafe - css-global-utilities.css: reglas body.roi-hide-* como respaldo ## Fix AdSense (Inc/adsense-placement.php) - Agregado PageVisibilityHelper::shouldShow() a todas las funciones: roi_render_ad_slot, roi_render_rail_ads, roi_enqueue_adsense_script, roi_inject_content_ads, roi_render_anchor_ads, roi_render_vignette_ad, roi_enqueue_anchor_vignette_scripts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Infrastructure\Persistence\WordPress;
|
||||
|
||||
use ROITheme\Shared\Domain\Contracts\WrapperVisibilityCheckerInterface;
|
||||
use ROITheme\Shared\Infrastructure\Services\PageVisibilityHelper;
|
||||
|
||||
/**
|
||||
* Implementación de WrapperVisibilityCheckerInterface para WordPress
|
||||
*
|
||||
* Responsabilidad: Consultar BD y evaluar visibilidad de wrappers de componentes
|
||||
*
|
||||
* - Consulta tabla wp_roi_theme_component_settings para is_enabled, show_on_mobile, show_on_desktop
|
||||
* - Delega evaluación de exclusiones a PageVisibilityHelper (DRY)
|
||||
*
|
||||
* @package ROITheme\Shared\Infrastructure\Persistence\WordPress
|
||||
* @see Plan 99.15 - Fix Empty Layout Wrappers
|
||||
*/
|
||||
final class WordPressComponentVisibilityRepository implements WrapperVisibilityCheckerInterface
|
||||
{
|
||||
private string $tableName;
|
||||
|
||||
public function __construct(
|
||||
private \wpdb $wpdb
|
||||
) {
|
||||
$this->tableName = $this->wpdb->prefix . 'roi_theme_component_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEnabled(string $componentName): bool
|
||||
{
|
||||
$value = $this->getVisibilityAttribute($componentName, 'is_enabled');
|
||||
|
||||
// Si no existe el registro, asumir habilitado por defecto
|
||||
if ($value === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->toBool($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isVisibleOnDevice(string $componentName, bool $isMobile): bool
|
||||
{
|
||||
$attribute = $isMobile ? 'show_on_mobile' : 'show_on_desktop';
|
||||
$value = $this->getVisibilityAttribute($componentName, $attribute);
|
||||
|
||||
// Si no existe el registro, asumir visible por defecto
|
||||
if ($value === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->toBool($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Delega a PageVisibilityHelper que ya implementa:
|
||||
* - Visibilidad por tipo de página (home, posts, pages, archives, search)
|
||||
* - Exclusiones por categoría, post ID, URL pattern
|
||||
*/
|
||||
public function isNotExcluded(string $componentName): bool
|
||||
{
|
||||
return PageVisibilityHelper::shouldShow($componentName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un atributo del grupo visibility desde la BD
|
||||
*
|
||||
* @param string $componentName
|
||||
* @param string $attributeName
|
||||
* @return string|null
|
||||
*/
|
||||
private function getVisibilityAttribute(string $componentName, string $attributeName): ?string
|
||||
{
|
||||
$sql = $this->wpdb->prepare(
|
||||
"SELECT attribute_value
|
||||
FROM {$this->tableName}
|
||||
WHERE component_name = %s
|
||||
AND group_name = %s
|
||||
AND attribute_name = %s
|
||||
LIMIT 1",
|
||||
$componentName,
|
||||
'visibility',
|
||||
$attributeName
|
||||
);
|
||||
|
||||
$result = $this->wpdb->get_var($sql);
|
||||
|
||||
return $result !== null ? (string) $result : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convierte string a boolean
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
private function toBool(string $value): bool
|
||||
{
|
||||
return $value === '1' || strtolower($value) === 'true';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user