Files
WP-LIT-MCP/src/Admin/AdminNotices.php
T

80 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Admin;
/**
* Admin notices for administrators (Etappe-0 follow-up d). Uses only cached check
* results so no HTTP request runs on ordinary admin page loads.
*/
final class AdminNotices
{
public function __construct(private ConnectionStatus $status)
{
}
public function register(): void
{
add_action('admin_notices', [$this, 'render']);
}
/** @return list<string> */
public function messages(bool $onOwnPage): array
{
$messages = [];
if (! $this->status->oauthEnabled()) {
$messages[] = __(
'LIT MCP: Der OAuth-Server ist deaktiviert (Filter wpmedia_mcp_oauth_server_enabled).',
'wp-lit-mcp'
) . ' ' . __('Claude kann sich nicht verbinden.', 'wp-lit-mcp');
}
/*
* Fire whenever the cached discovery result is not 'good' (this also covers
* 'recommended', which is how HealthCheck::run_self_check() itself reports both
* a genuine reachability problem and its acme-challenge-fingerprint "critical"
* case) — but only when oauth is enabled and permalinks are pretty. Those two
* conditions are exactly when run_self_check() short-circuits to its own
* disabled/permalink-missing early returns instead of a real check; guarding on
* them here (rather than trying to recognise their shape from the cached array)
* keeps this correct even though, in the vendor's current implementation,
* neither early return is ever persisted to the transient we read.
*/
$discovery = $this->status->discovery(false);
if (
$this->status->oauthEnabled()
&& $this->status->permalinksPretty()
&& is_array($discovery)
&& ($discovery['status'] ?? 'good') !== 'good'
) {
$messages[] = __(
'LIT MCP: Die OAuth-Discovery-Dokumente unter /.well-known/ sind nicht erreichbar.',
'wp-lit-mcp'
) . ' ' . __('Details unter Werkzeuge → Website-Zustand.', 'wp-lit-mcp');
}
if ($onOwnPage && ! $this->status->https()) {
$messages[] = __(
'LIT MCP: Die Website läuft ohne HTTPS; claude.ai verbindet sich nur mit HTTPS-Websites.',
'wp-lit-mcp'
);
}
return $messages;
}
public function render(): void
{
if (! current_user_can('manage_options')) {
return;
}
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
$onOwnPage = is_object($screen) && $screen->id === 'settings_page_' . SettingsPage::SLUG;
foreach ($this->messages($onOwnPage) as $message) {
printf('<div class="notice notice-warning"><p>%s</p></div>', esc_html($message));
}
}
}