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

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

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:''

Return

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

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

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.