refactor: Divi-Boot-Schritte in DiviIntegration::boot() (Bootable) – Upgrader-Hook, Prüf-Route, CLI und Reiter „Divi“ über lit_mcp_admin_tabs; IntegrationRegistry::boot() bootet jede Integration genau einmal; Prüfseiten-Aufräumen im load-Hook statt beim Rendern
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
06148fb8c1
commit
6c59934caa
+33
-13
@@ -16,24 +16,27 @@ final class SettingsPage
|
||||
/** Hook suffix WordPress gives this page (add_options_page → "settings_page_<slug>"). */
|
||||
public const SCREEN_HOOK = 'settings_page_' . self::SLUG;
|
||||
|
||||
/** @var array<string, AdminTab> */
|
||||
private array $tabs = [];
|
||||
/**
|
||||
* Filter on the tab list (list<AdminTab>): 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<string, AdminTab>|null null = TABS_FILTER not applied yet. */
|
||||
private ?array $tabs = null;
|
||||
|
||||
/**
|
||||
* @param list<AdminTab> $tabs The first tab is the default.
|
||||
* @param list<AdminTab> $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.
|
||||
*/
|
||||
public function __construct(
|
||||
array $tabs,
|
||||
private array $baseTabs,
|
||||
private string $logoUrl = '',
|
||||
private string $assetsUrl = '',
|
||||
private string $version = ''
|
||||
) {
|
||||
foreach ($tabs as $tab) {
|
||||
$this->tabs[$tab->slug()] = $tab;
|
||||
}
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
@@ -41,7 +44,7 @@ final class SettingsPage
|
||||
add_action('admin_menu', [$this, 'addMenu']);
|
||||
add_action('admin_init', [$this, 'registerSettings']);
|
||||
add_action('admin_enqueue_scripts', [$this, 'enqueueAssets']);
|
||||
foreach ($this->tabs as $tab) {
|
||||
foreach ($this->tabs() as $tab) {
|
||||
$tab->registerActions();
|
||||
}
|
||||
}
|
||||
@@ -59,7 +62,7 @@ final class SettingsPage
|
||||
|
||||
public function registerSettings(): void
|
||||
{
|
||||
foreach ($this->tabs as $tab) {
|
||||
foreach ($this->tabs() as $tab) {
|
||||
$tab->registerSettings();
|
||||
}
|
||||
}
|
||||
@@ -90,7 +93,7 @@ final class SettingsPage
|
||||
/** @return list<string> */
|
||||
public function tabSlugs(): array
|
||||
{
|
||||
return array_keys($this->tabs);
|
||||
return array_keys($this->tabs());
|
||||
}
|
||||
|
||||
public function currentTab(): string
|
||||
@@ -98,7 +101,9 @@ final class SettingsPage
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab switch.
|
||||
$requested = isset($_GET['tab']) ? sanitize_key(wp_unslash((string) $_GET['tab'])) : '';
|
||||
|
||||
return isset($this->tabs[$requested]) ? $requested : (string) array_key_first($this->tabs);
|
||||
$tabs = $this->tabs();
|
||||
|
||||
return isset($tabs[$requested]) ? $requested : (string) array_key_first($tabs);
|
||||
}
|
||||
|
||||
/** @param array<string, string> $args */
|
||||
@@ -123,7 +128,7 @@ final class SettingsPage
|
||||
echo '</div><hr class="wp-header-end">';
|
||||
$this->renderNotice();
|
||||
printf('<nav class="nav-tab-wrapper wp-clearfix" aria-label="%s">', esc_attr__('Bereiche', 'wp-lit-mcp'));
|
||||
foreach ($this->tabs as $slug => $tab) {
|
||||
foreach ($this->tabs() as $slug => $tab) {
|
||||
printf(
|
||||
'<a href="%s" class="nav-tab%s"%s>%s</a>',
|
||||
esc_url(self::url($slug)),
|
||||
@@ -133,10 +138,25 @@ final class SettingsPage
|
||||
);
|
||||
}
|
||||
echo '</nav>';
|
||||
$this->tabs[$current]->render();
|
||||
$this->tabs()[$current]->render();
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/** @return array<string, AdminTab> 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 === '') {
|
||||
|
||||
Reference in New Issue
Block a user