"). */ public const SCREEN_HOOK = 'settings_page_' . self::SLUG; /** * Filter on the tab list (list): integrations append their own tabs in Bootable::boot() – Divi its * tab "Divi". Applied once, on first use of the tabs (after Plugin booted the integrations). */ public const TABS_FILTER = 'lit_mcp_admin_tabs'; /** @var array|null null = TABS_FILTER not applied yet. */ private ?array $tabs = null; /** * @param list $baseTabs The plugin's own tabs; the first tab is the default. * @param string $logoUrl Loosen-IT logo shown top right of the page ('' = none). * @param string $assetsUrl URL of the plugin's assets/ directory ('' = no own CSS/JS). * @param string $version Asset version for cache busting. * @param (Closure(string): ?string)|null $profileLabel Label of a compatibility profile by ID, null = unknown; * names the profile in the compat_* notices. */ public function __construct( private array $baseTabs, private string $logoUrl = '', private string $assetsUrl = '', private string $version = '', private ?Closure $profileLabel = null ) { } public function register(): void { add_action('admin_menu', [$this, 'addMenu']); add_action('admin_init', [$this, 'registerSettings']); add_action('admin_enqueue_scripts', [$this, 'enqueueAssets']); add_filter('removable_query_args', [$this, 'removableQueryArgs']); foreach ($this->tabs() as $tab) { $tab->registerActions(); } } public function addMenu(): void { $hook = add_options_page( __('LIT MCP', 'wp-lit-mcp'), __('LIT MCP', 'wp-lit-mcp'), 'manage_options', self::SLUG, [$this, 'render'] ); if (is_string($hook)) { add_action('load-' . $hook, [$this, 'addHelpTab']); } } /** * WordPress removes these from the address bar after the page loaded, so a reload or a copied link * does not show a finished action's notice again. * * @param array $args * @return array */ public function removableQueryArgs(array $args): array { $args[] = 'lit_mcp_notice'; $args[] = 'lit_mcp_profile'; return $args; } /** Short "Hilfe" panel at the top right; the tabs explain themselves, this only says where to start. */ public function addHelpTab(): void { $screen = get_current_screen(); if ($screen !== null) { $this->helpTabFor($screen); } } /** @param object $screen A WP_Screen. */ public function helpTabFor(object $screen): void { $items = [ __('Verbinden', 'wp-lit-mcp') => __( 'Tab „Verbindung“: Server-URL kopieren und im KI-Assistenten als MCP-Server hinzufügen.', 'wp-lit-mcp' ), __('Wer darf?', 'wp-lit-mcp') => __( 'Tab „Zugriff“: Rollen festlegen und bestehende Verbindungen widerrufen.', 'wp-lit-mcp' ), __('Was darf der Assistent?', 'wp-lit-mcp') => __( 'Tab „Tools“: jedes Tool direkt, indirekt oder aus; ganze Gruppen auf „nur lesen“ stellen.', 'wp-lit-mcp' ), __('Was ist passiert?', 'wp-lit-mcp') => __( 'Tab „Protokoll“: jede Änderung des Assistenten mit Benutzer, Ergebnis und Zeitpunkt.', 'wp-lit-mcp' ), __('Passt es zu Divi, Pods & Co.?', 'wp-lit-mcp') => __( 'Tab „Kompatibilität“: Fremd-Plugins prüfen, Versionen freigeben und sehen, was gesperrt ist.', 'wp-lit-mcp' ), ]; $content = ''; foreach ($items as $title => $text) { $content .= sprintf('

%s %s

', esc_html($title), esc_html($text)); } $screen->add_help_tab([ 'id' => 'lit-mcp-overview', 'title' => __('Überblick', 'wp-lit-mcp'), 'content' => $content, ]); } public function registerSettings(): void { foreach ($this->tabs() as $tab) { $tab->registerSettings(); } } /** * Own CSS and a small script, only on this page. The script builds on WordPress' own * clipboard.js and wp.a11y.speak (as the media modal's "Copy URL") and postbox.js. */ public function enqueueAssets(string $hook): void { if ($hook !== self::SCREEN_HOOK || $this->assetsUrl === '') { return; } $base = rtrim($this->assetsUrl, '/'); wp_enqueue_style('lit-mcp-admin', $base . '/css/admin.css', [], $this->version); $deps = ['clipboard', 'wp-a11y']; if ($this->currentTab() === 'tools') { // Collapsible tool groups use WordPress' own postbox toggles (remembered per user). $deps[] = 'postbox'; } wp_enqueue_script('lit-mcp-admin', $base . '/js/admin.js', $deps, $this->version, true); wp_localize_script('lit-mcp-admin', 'litMcpAdmin', [ 'copied' => __('Die URL wurde in die Zwischenablage kopiert.', 'wp-lit-mcp'), /* translators: %d: number of tools matching the filter */ 'toolsShown' => __('%d Tools angezeigt', 'wp-lit-mcp'), 'toolShown' => __('1 Tool angezeigt', 'wp-lit-mcp'), 'groupReset' => __('Gruppe auf Standard zurückgesetzt. Noch nicht gespeichert.', 'wp-lit-mcp'), ]); } /** @return list */ public function tabSlugs(): array { return array_keys($this->tabs()); } public function currentTab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab switch. $requested = is_string($_GET['tab'] ?? null) ? sanitize_key(wp_unslash($_GET['tab'])) : ''; $tabs = $this->tabs(); return isset($tabs[$requested]) ? $requested : (string) array_key_first($tabs); } /** @param array $args */ public static function url(string $tab = '', array $args = []): string { $query = array_merge(['page' => self::SLUG], $tab !== '' ? ['tab' => $tab] : [], $args); return add_query_arg($query, admin_url('options-general.php')); } public function render(): void { if (! current_user_can('manage_options')) { return; } $current = $this->currentTab(); echo '
'; echo '

' . esc_html__('LIT MCP', 'wp-lit-mcp') . '

'; $this->renderLogo(); // Admin notices of other plugins are moved right after this marker – above the tabs. echo '

'; $this->renderNotice(); printf(''; $this->tabs()[$current]->render(); echo '
'; } /** @return array The plugin's tabs and those the integrations add (TABS_FILTER), by slug. */ private function tabs(): array { if ($this->tabs === null) { $this->tabs = []; foreach ((array) apply_filters(self::TABS_FILTER, $this->baseTabs) as $tab) { if ($tab instanceof AdminTab) { $this->tabs[$tab->slug()] = $tab; } } } return $this->tabs; } private function renderLogo(): void { if ($this->logoUrl === '') { return; } printf( '' . '' . ' %s', esc_url($this->logoUrl), esc_html__('(öffnet in einem neuen Tab)', 'wp-lit-mcp') ); } /** "