@@ -58,7 +58,8 @@ function wp_is_connector_registered( string $id ): bool {
5858 * @type array $plugin {
5959 * Optional. Plugin data for install/activate UI.
6060 *
61- * @type string $slug The WordPress.org plugin slug.
61+ * @type string $file The plugin's main file path relative to the plugins
62+ * directory (e.g. 'akismet/akismet.php' or 'hello.php').
6263 * }
6364 * }
6465 * @phpstan-return ?array{
@@ -74,7 +75,7 @@ function wp_is_connector_registered( string $id ): bool {
7475 * env_var_name?: non-empty-string
7576 * },
7677 * plugin?: array{
77- * slug : non-empty-string
78+ * file : non-empty-string
7879 * }
7980 * }
8081 */
@@ -118,7 +119,8 @@ function wp_get_connector( string $id ): ?array {
118119 * @type array $plugin {
119120 * Optional. Plugin data for install/activate UI.
120121 *
121- * @type string $slug The WordPress.org plugin slug.
122+ * @type string $file The plugin's main file path relative to the plugins
123+ * directory (e.g. 'akismet/akismet.php' or 'hello.php').
122124 * }
123125 * }
124126 * }
@@ -135,7 +137,7 @@ function wp_get_connector( string $id ): ?array {
135137 * env_var_name?: non-empty-string
136138 * },
137139 * plugin?: array{
138- * slug : non-empty-string
140+ * file : non-empty-string
139141 * }
140142 * }>
141143 */
@@ -256,7 +258,7 @@ function _wp_connectors_register_default_ai_providers( WP_Connector_Registry $re
256258 'description ' => __ ( 'Text generation with Claude. ' ),
257259 'type ' => 'ai_provider ' ,
258260 'plugin ' => array (
259- 'slug ' => 'ai-provider-for-anthropic ' ,
261+ 'file ' => 'ai-provider-for-anthropic/plugin.php ' ,
260262 ),
261263 'authentication ' => array (
262264 'method ' => 'api_key ' ,
@@ -268,7 +270,7 @@ function _wp_connectors_register_default_ai_providers( WP_Connector_Registry $re
268270 'description ' => __ ( 'Text and image generation with Gemini and Imagen. ' ),
269271 'type ' => 'ai_provider ' ,
270272 'plugin ' => array (
271- 'slug ' => 'ai-provider-for-google ' ,
273+ 'file ' => 'ai-provider-for-google/plugin.php ' ,
272274 ),
273275 'authentication ' => array (
274276 'method ' => 'api_key ' ,
@@ -280,7 +282,7 @@ function _wp_connectors_register_default_ai_providers( WP_Connector_Registry $re
280282 'description ' => __ ( 'Text and image generation with GPT and Dall-E. ' ),
281283 'type ' => 'ai_provider ' ,
282284 'plugin ' => array (
283- 'slug ' => 'ai-provider-for-openai ' ,
285+ 'file ' => 'ai-provider-for-openai/plugin.php ' ,
284286 ),
285287 'authentication ' => array (
286288 'method ' => 'api_key ' ,
@@ -636,15 +638,9 @@ function _wp_connectors_pass_default_keys_to_ai_client(): void {
636638function _wp_connectors_get_connector_script_module_data ( array $ data ): array {
637639 $ registry = AiClient::defaultRegistry ();
638640
639- // Build a slug-to-file map for plugin installation status.
640- if ( ! function_exists ( 'get_plugins ' ) ) {
641+ if ( ! function_exists ( 'is_plugin_active ' ) ) {
641642 require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
642643 }
643- $ plugin_files_by_slug = array ();
644- foreach ( array_keys ( get_plugins () ) as $ plugin_file ) {
645- $ slug = str_contains ( $ plugin_file , '/ ' ) ? dirname ( $ plugin_file ) : str_replace ( '.php ' , '' , $ plugin_file );
646- $ plugin_files_by_slug [ $ slug ] = $ plugin_file ;
647- }
648644
649645 $ connectors = array ();
650646 foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
@@ -676,18 +672,14 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
676672 'authentication ' => $ auth_out ,
677673 );
678674
679- if ( ! empty ( $ connector_data ['plugin ' ]['slug ' ] ) ) {
680- $ plugin_slug = $ connector_data ['plugin ' ]['slug ' ];
681- $ plugin_file = $ plugin_files_by_slug [ $ plugin_slug ] ?? null ;
682-
683- $ is_installed = null !== $ plugin_file ;
684- $ is_activated = $ is_installed && is_plugin_active ( $ plugin_file );
675+ if ( ! empty ( $ connector_data ['plugin ' ]['file ' ] ) ) {
676+ $ file = $ connector_data ['plugin ' ]['file ' ];
677+ $ is_installed = file_exists ( wp_normalize_path ( WP_PLUGIN_DIR . '/ ' . $ file ) );
678+ $ is_activated = $ is_installed && is_plugin_active ( $ file );
685679
686680 $ connector_out ['plugin ' ] = array (
687- 'slug ' => $ plugin_slug ,
688- 'pluginFile ' => $ is_installed
689- ? ( str_ends_with ( $ plugin_file , '.php ' ) ? substr ( $ plugin_file , 0 , -4 ) : $ plugin_file )
690- : null ,
681+ 'file ' => $ file ,
682+ 'isInstalled ' => $ is_installed ,
691683 'isActivated ' => $ is_activated ,
692684 );
693685 }
0 commit comments