wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



_wp_connectors_get_api_key_source › WordPress Function

Seit7.0.0
Veraltetn/v
_wp_connectors_get_api_key_source ( $setting_name, $env_var_name = '', $constant_name = '' )
Zugriff:
  • private
Parameter: (3)
  • (string) $setting_name The option name for the API key (e.g., 'connectors_spam_filtering_my_plugin_api_key').
    Erforderlich: Ja
  • (string) $env_var_name Optional. Environment variable name to check (e.g., 'MY_PLUGIN_API_KEY').
    Erforderlich: Nein
    Standard: (leer)
  • (string) $constant_name Optional. PHP constant name to check (e.g., 'MY_PLUGIN_API_KEY').
    Erforderlich: Nein
    Standard: (leer)
Gibt zurück:
  • (string) The key source: 'env', 'constant', 'database', or 'none'.
Definiert in:
Codex:

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

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


Quellcode

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';
}