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} * * Evalúa múltiples criterios de exclusión: * - hide_for_logged_in: Ocultar para usuarios logueados * - 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 { // Verificar hide_for_logged_in if ($this->shouldHideForLoggedIn($componentName)) { return false; } return PageVisibilityHelper::shouldShow($componentName); } /** * Verifica si debe ocultarse para usuarios logueados */ private function shouldHideForLoggedIn(string $componentName): bool { $value = $this->getVisibilityAttribute($componentName, 'hide_for_logged_in'); if ($value === null) { return false; } return $this->toBool($value) && is_user_logged_in(); } /** * 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'; } }