tools = new Tools_Registry(); $this->resolver = new Tool_Resolver(); $this->endpoints = new Endpoints( $this->resolver ); $this->attach_hooks(); } private function attach_hooks(): void { $late_or_now = function ( string $action, callable $cb ) { did_action( $action ) ? $cb() : add_action( $action, $cb ); }; $late_or_now( 'wp_abilities_api_categories_init', [ $this->tools, 'setup_category' ] ); $late_or_now( 'wp_abilities_api_init', [ $this->tools, 'setup_tools' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'load_bridge' ] ); add_action( 'activate_plugin', [ $this->resolver, 'flush' ] ); add_action( 'deactivate_plugin', [ $this->resolver, 'flush' ] ); } public function load_bridge(): void { if ( ! is_ssl() || ! apply_filters( 'webmcp_load_bridge', true ) ) { return; } wp_enqueue_script( 'webmcp-bridge', WEBMCP_URL . 'webmcp.js', [], WEBMCP_VER, [ 'strategy' => 'defer' ] ); $cfg = wp_json_encode( [ 'tools' => rest_url( 'webmcp/v1/tools' ), 'run' => rest_url( 'webmcp/v1/execute/' ), 'refresh' => rest_url( 'webmcp/v1/nonce' ), 'token' => wp_create_nonce( 'webmcp_run' ), ] ); wp_add_inline_script( 'webmcp-bridge', 'var webmcpConfig=' . $cfg . ';', 'before' ); } }