*/ const ABILITIES = [ 'mcp-adapter/discover-abilities' => DiscoverAbilitiesAbility::class, 'mcp-adapter/get-ability-info' => GetAbilityInfoAbility::class, 'mcp-adapter/execute-ability' => ExecuteAbilityAbility::class, ]; /** * Register WordPress hooks. * * @return void * @since 1.4.3 */ public function register_hooks(): void { add_action( 'wp_abilities_api_categories_init', [ $this, 'register_category' ], self::PRIORITY ); add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ], self::PRIORITY ); } /** * Register the `mcp-adapter` category if it is missing. * * @return void * @since 1.4.3 */ public function register_category(): void { if ( ! function_exists( 'wp_register_ability_category' ) || wp_has_ability_category( self::CATEGORY ) ) { return; } // Same untranslated strings the adapter uses, so the category reads the same whoever registered it. wp_register_ability_category( self::CATEGORY, [ 'label' => 'MCP Adapter', 'description' => 'Abilities for the MCP Adapter', ] ); } /** * Register each missing ability through the adapter's own class. * * @return void * @since 1.4.3 */ public function register_abilities(): void { if ( ! function_exists( 'wp_register_ability' ) || ! wp_has_ability_category( self::CATEGORY ) ) { return; } foreach ( self::ABILITIES as $id => $class ) { // The loaded adapter copy may be another plugin's; skip what it does not provide. if ( wp_has_ability( $id ) || ! method_exists( $class, 'register' ) ) { continue; } $class::register(); } } }