Determines the source of an API key for a given connector.
Description
Checks in order: environment variable, PHP constant, database.
Environment variable and constant are only checked when their respective names are provided.
Parameters
$setting_namestringrequired- The option name for the API key (e.g.,
'connectors_spam_filtering_my_plugin_api_key'). $env_var_namestringoptional- Environment variable name to check (e.g.,
'MY_PLUGIN_API_KEY').Default:
'' $constant_namestringoptional- PHP constant name to check (e.g.,
'MY_PLUGIN_API_KEY').Default:
''
Source
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';
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.