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'; } }