ram Context $context OAuth server context. * @return void */ private function register_discovery( Context $context ): void { $discovery = new DiscoveryEndpoints( $context ); add_action( 'init', [ $discovery, 'add_rewrite_rules' ] ); add_filter( 'query_vars', [ $discovery, 'add_query_vars' ] ); add_action( 'template_redirect', [ $discovery, 'handle_request' ] ); } /** * Wire the Site Health self-check for the .well-known discovery documents. * * @param Context $context OAuth server context. * @return void */ private function register_discovery_health_check( Context $context ): void { $health_check = new DiscoveryHealthCheck( $context ); add_filter( 'site_status_tests', [ $health_check, 'add_test' ] ); } /** * Wire MCP server + abilities registration. * * @param Context $context OAuth server context. * @return void */ private function register_transport( Context $context ): void { $registrar = new ServerRegistrar( new Server( $context ), $context ); add_action( 'wp_abilities_api_categories_init', [ $registrar, 'ensure_default_category' ] ); add_action( 'wp_abilities_api_init', [ $registrar, 'ensure_shared_abilities_registered' ] ); add_action( 'mcp_adapter_init', [ $registrar, 'register_server' ] ); } /** * Lazily flush rewrite rules once per REWRITE_VERSION bump. * * Runs after rewrite rules are (re-)registered on the same 'init' action * (priority 10), so the rules exist before being persisted. * * @return void */ public function maybe_flush_rewrite_rules(): void { if ( ! $this->context->is_enabled() ) { return; } if ( ! $this->needs_rewrite_flush() ) { return; } flush_rewrite_rules( false ); update_option( self::REWRITE_OPTION, self::REWRITE_VERSION, false ); } /** * Whether the OAuth rewrite rules need to be (re-)persisted. * * Self-heals cases the version flag alone cannot detect: a fresh site, a * filter/snippet that enables the server only after init@20 on the previous * load, or our rules dropped from the persisted set. When pretty permalinks * are off, the rules can never be persisted, so a flag match alone is used * to avoid flushing on every request. * * @return bool */ private function needs_rewrite_flush(): bool { if ( get_option( self::REWRITE_OPTION ) !== self::REWRITE_VERSION ) { return true; } // Plain permalinks: no pretty rules to check; a flag match is enough. if ( '' === (string) get_option( 'permalink_structure' ) ) { return false; } $rules = get_option( 'rewrite_rules' ); return ! is_array( $rules ) || ! array_key_exists( Rewrite::AUTHORIZE_RULE, $rules ); } /** * Force the next 'init' to re-flush rewrite rules. * * Call this whenever whatever flips the `wpmedia_mcp_oauth_server_enabled` * filter changes state — a version-flag match alone cannot detect that. * * @return void */ public static function schedule_rewrite_flush(): void { delete_option( self::REWRITE_OPTION ); } } https://www.traphan.de/page-sitemap.xml 2025-03-28T09:01:48+00:00 https://www.traphan.de/local-sitemap.xml 2024-07-12T12:42:25+00:00