Transport identifier => STATE_* constant. */ public static function detect_all(): array { return array( self::TRANSPORT_MCP_MANAGER => self::detect( self::TRANSPORT_MCP_MANAGER ), self::TRANSPORT_MCP_ADAPTER => self::detect( self::TRANSPORT_MCP_ADAPTER ), self::TRANSPORT_ELEMENTOR_MCP => self::detect( self::TRANSPORT_ELEMENTOR_MCP ), ); } /** * Detect the recommended transport by plugin file. * * @since 0.0.34 * @return string One of the STATE_* constants. */ private static function detect_mcp_manager(): string { self::require_plugin_api(); if ( is_plugin_active( self::MCP_MANAGER_BASENAME ) ) { return self::STATE_ACTIVE; } if ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( self::MCP_MANAGER_BASENAME ) ) { return self::STATE_ACTIVE; } $installed = function_exists( 'get_plugins' ) ? get_plugins() : array(); return array_key_exists( self::MCP_MANAGER_BASENAME, $installed ) ? self::STATE_INACTIVE : self::STATE_MISSING; } /** * Detect the standalone MCP Adapter plugin. * * The plugin file is authoritative. A loaded `WP\MCP\Core\*` class is NOT evidence of it — * see the note in the body for what that cost. * * @since 0.0.34 * @return string One of the STATE_* constants. */ private static function detect_mcp_adapter(): string { self::require_plugin_api(); $installed = function_exists( 'get_plugins' ) ? get_plugins() : array(); $found = false; foreach ( self::mcp_adapter_basename_candidates() as $basename ) { if ( ! array_key_exists( $basename, $installed ) ) { continue; } $found = true; if ( function_exists( 'is_plugin_active' ) && is_plugin_active( $basename ) ) { return self::STATE_ACTIVE; } } if ( $found ) { return self::STATE_INACTIVE; } /* * The adapter LIBRARY may still be loaded at this point, and until 0.0.42 that was read as * "active". It is not the same thing, and the difference is now common rather than * theoretical: Elementor ships `wordpress/mcp-adapter` inside its own vendor directory, as * does AcrossAI MCP Manager. On this site `WP\MCP\Core\McpAdapter` resolved out of * Elementor while `mcp-adapter/mcp-adapter.php` sat installed and switched off — and the * Quick Connect card happily reported "Already active" for a plugin the operator had never * turned on, hiding the Activate button that would have fixed it. * * So the plugin is the authority here, because the plugin is what this answer is about: the * card offers to install or activate one, and neither action exists for a library vendored * inside somebody else's plugin. */ return self::STATE_MISSING; } /** * Plugin basenames that may hold a standalone MCP Adapter install. * * @since 0.0.34 * @return string[] Plugin basenames, filterable. */ private static function mcp_adapter_basename_candidates(): array { $candidates = array( 'mcp-adapter/mcp-adapter.php', 'wordpress-mcp-adapter/mcp-adapter.php', ); /** * Filters the plugin basenames checked for a standalone MCP Adapter. * * @since 0.0.34 * @param string[] $candidates Plugin basenames. */ return (array) apply_filters( 'acrossai_mcp_adapter_basename_candidates', $candidates ); } /** * Ensure the WordPress plugin API is loaded. * * Detection runs on front-end and REST requests too, where * wp-admin/includes/plugin.php is not loaded by default. * * @since 0.0.34 * @return void */ private static function require_plugin_api(): void { if ( ! function_exists( 'is_plugin_active' ) && defined( 'ABSPATH' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } } }