Registered tabs, keyed by id. */ private static array $tabs = []; /** @var array Registered platform providers. */ private static array $platforms = []; /** * Register a settings tab. * * @param array $tab { * @type string $id Required. Unique slug, e.g. 'woocommerce'. Used in the URL and DOM id. * @type string $label Required. Human label shown on the tab, e.g. 'WooCommerce'. * @type callable $render Required. Echoes the tab panel markup. * @type string $icon Optional. Inline SVG string shown before the label. * @type int $priority Optional. Lower sorts first. Default 50. * } */ public static function register_tab(array $tab): void { if (empty($tab['id']) || empty($tab['label']) || !isset($tab['render']) || !is_callable($tab['render'])) { return; } $tab = array_merge(['icon' => '', 'priority' => 50], $tab); self::$tabs[$tab['id']] = $tab; } /** * @return array Registered tabs sorted by priority then label. */ public static function get_tabs(): array { $tabs = self::$tabs; uasort($tabs, static function ($a, $b) { return $a['priority'] <=> $b['priority'] ?: strcasecmp($a['label'], $b['label']); }); return $tabs; } /** * Register a platform provider. * * @param string $name Platform identifier persisted on tracking rows, e.g. 'woocommerce'. * @param callable $is_active Returns true when this platform's checkout is active. * @param int $priority Reserved (accepted for forward compatibility). Resolution no * longer ranks by priority: a single active provider wins, and * multiple active providers resolve to 'wordpress' (ambiguous). */ public static function register_platform(string $name, callable $is_active, int $priority = 50): void { self::$platforms[] = [ 'name' => $name, 'is_active' => $is_active, 'priority' => $priority, ]; } public static function resolve_platform(): string { $active = []; foreach (self::$platforms as $provider) { try { if (call_user_func($provider['is_active'])) { $active[] = $provider['name']; } } catch (\Throwable $e) { // A misbehaving provider must never break frontend enqueueing. \AdvocateLoop\Core\Logger::warning('Platform provider threw', [ 'platform' => $provider['name'], 'error' => $e->getMessage(), ]); } } $active = array_values(array_unique($active)); return (count($active) === 1) ? $active[0] : 'wordpress'; } }