@@ -347,10 +347,11 @@ function _wp_connectors_mask_api_key( string $key ): string {
347347 * @since 7.0.0
348348 * @access private
349349 *
350- * @param string $provider_id The provider ID (e.g., 'openai', 'anthropic', 'google').
350+ * @param string $provider_id The provider ID (e.g., 'openai', 'anthropic', 'google').
351+ * @param string $setting_name The option name for the API key (e.g., 'connectors_ai_openai_api_key').
351352 * @return string The key source: 'env', 'constant', 'database', or 'none'.
352353 */
353- function _wp_connectors_get_api_key_source ( string $ provider_id ): string {
354+ function _wp_connectors_get_api_key_source ( string $ provider_id, string $ setting_name ): string {
354355 // Convert provider ID to CONSTANT_CASE for env var name.
355356 // e.g., 'openai' -> 'OPENAI', 'anthropic' -> 'ANTHROPIC'.
356357 $ constant_case_id = strtoupper (
@@ -373,8 +374,7 @@ function _wp_connectors_get_api_key_source( string $provider_id ): string {
373374 }
374375
375376 // Check database.
376- $ setting_name = "connectors_ai_ {$ provider_id }_api_key " ;
377- $ db_value = get_option ( $ setting_name , '' );
377+ $ db_value = get_option ( $ setting_name , '' );
378378 if ( '' !== $ db_value ) {
379379 return 'database ' ;
380380 }
@@ -452,7 +452,7 @@ function _wp_connectors_rest_settings_dispatch( WP_REST_Response $response, WP_R
452452
453453 foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
454454 $ auth = $ connector_data ['authentication ' ];
455- if ( 'api_key ' !== $ auth ['method ' ] || empty ( $ auth ['setting_name ' ] ) ) {
455+ if ( 'ai_provider ' !== $ connector_data [ ' type ' ] || ' api_key ' !== $ auth ['method ' ] || empty ( $ auth ['setting_name ' ] ) ) {
456456 continue ;
457457 }
458458
@@ -551,7 +551,7 @@ function _wp_connectors_pass_default_keys_to_ai_client(): void {
551551 }
552552
553553 // Skip if the key is already provided via env var or constant.
554- $ key_source = _wp_connectors_get_api_key_source ( $ connector_id );
554+ $ key_source = _wp_connectors_get_api_key_source ( $ connector_id, $ auth [ ' setting_name ' ] );
555555 if ( 'env ' === $ key_source || 'constant ' === $ key_source ) {
556556 continue ;
557557 }
@@ -602,7 +602,7 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
602602 if ( 'api_key ' === $ auth ['method ' ] ) {
603603 $ auth_out ['settingName ' ] = $ auth ['setting_name ' ] ?? '' ;
604604 $ auth_out ['credentialsUrl ' ] = $ auth ['credentials_url ' ] ?? null ;
605- $ auth_out ['keySource ' ] = _wp_connectors_get_api_key_source ( $ connector_id );
605+ $ auth_out ['keySource ' ] = _wp_connectors_get_api_key_source ( $ connector_id, $ auth [ ' setting_name ' ] ?? '' );
606606 try {
607607 $ auth_out ['isConnected ' ] = $ registry ->hasProvider ( $ connector_id ) && $ registry ->isProviderConfigured ( $ connector_id );
608608 } catch ( Exception $ e ) {
0 commit comments