Title: _wp_connectors_get_api_key_source
Published: May 20, 2026

---

# _wp_connectors_get_api_key_source( string $setting_name, string $env_var_name = '', string $constant_name = '' ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Determines the source of an API key for a given connector.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#description)󠁿

Checks in order: environment variable, PHP constant, database.
Environment variable
and constant are only checked when their respective names are provided.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#parameters)󠁿

 `$setting_name`stringrequired

The option name for the API key (e.g., `'connectors_spam_filtering_my_plugin_api_key'`).

`$env_var_name`stringoptional

Environment variable name to check (e.g., `'MY_PLUGIN_API_KEY'`).

Default:`''`

`$constant_name`stringoptional

PHP constant name to check (e.g., `'MY_PLUGIN_API_KEY'`).

Default:`''`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#return)󠁿

 string The key source: `'env'`, `'constant'`, `'database'`, or `'none'`.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#source)󠁿

    ```php
    function _wp_connectors_get_api_key_source( string $setting_name, string $env_var_name = '', string $constant_name = '' ): string {
    	// Check environment variable first.
    	if ( '' !== $env_var_name ) {
    		$env_value = getenv( $env_var_name );
    		if ( false !== $env_value && '' !== $env_value ) {
    			return 'env';
    		}
    	}

    	// Check PHP constant.
    	if ( '' !== $constant_name && defined( $constant_name ) ) {
    		$const_value = constant( $constant_name );
    		if ( is_string( $const_value ) && '' !== $const_value ) {
    			return 'constant';
    		}
    	}

    	// Check database.
    	$db_value = get_option( $setting_name, '' );
    	if ( '' !== $db_value ) {
    		return 'database';
    	}

    	return 'none';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/connectors.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/connectors.php#L440)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/connectors.php#L440-L464)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#related)󠁿

| Uses | Description | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

| Used by | Description | 
| [_wp_connectors_get_connector_script_module_data()](https://developer.wordpress.org/reference/functions/_wp_connectors_get_connector_script_module_data/)`wp-includes/connectors.php` |

Exposes connector settings to the connectors-wp-admin script module.

  | 
| [_wp_connectors_pass_default_keys_to_ai_client()](https://developer.wordpress.org/reference/functions/_wp_connectors_pass_default_keys_to_ai_client/)`wp-includes/connectors.php` |

Passes stored connector API keys to the WP AI client.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_wp_connectors_get_api_key_source/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_wp_connectors_get_api_key_source%2F)
before being able to contribute a note or feedback.