wppaste
WordPress

wp_connectors_get_application_password_credentials( array $auth ): array{username:

Since
7.1.0
Source
wp-includes/connectors.php:522
Resolves application-password credentials for a connector.

Description

Checks in order: environment variable, PHP constant, database. The environment variable and constant are only checked when their respective names are provided, and must contain the credentials as a single username:password string. A non-empty environment variable or constant that cannot be parsed as username:password is reported with _doing_it_wrong() and ignored, so resolution falls through to the next source.

Compatibility

WordPress
since 7.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$autharray
The connector's authentication configuration.

Return value

array{username:
string, password: string, source: string} Resolved credentials and their source: 'env', 'constant', 'database', or 'none'.

Performance profile

How much work a call to wp_connectors_get_application_password_credentials() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
33–115

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 132.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksdo_action()one call below wp_connectors_get_application_password_credentials()
  • cacheobject cachewp_cache_get()one call below wp_connectors_get_application_password_credentials()
  • serializeserialisationmaybe_unserialize()one call below wp_connectors_get_application_password_credentials()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 14 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_connectors_get_application_password_credentials() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$auth && $env_var_name === "" && $constant_name === ""33–50get_option()
!$auth && $env_var_name === "" && $constant_name !== "" && !defined()37–54defined(), get_option()
!$auth && $env_var_name === "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== ""37–38defined(), constant(), wp_connectors_parse_application_password_credentials()
!$auth && $env_var_name !== "" && $constant_name === ""39–58getenv(), get_option()
!$auth && $env_var_name === "" && $constant_name !== "" && defined()43–62defined(), constant(), get_option()
!$auth && $env_var_name !== "" && $constant_name !== "" && !defined()43–62getenv(), defined(), get_option()
!$auth && $env_var_name !== "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== ""43–46getenv(), defined(), constant(), wp_connectors_parse_application_password_credentials()
!$auth && $env_var_name !== "" && $constant_name !== "" && defined()49–70getenv(), defined(), constant(), get_option()
!$auth && $env_var_name !== "" && $env_value !== false && $env_value !== "" && $constant_name === ""63–79getenv(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), get_option()
!$auth && $env_var_name === "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== ""67–87defined(), constant(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), get_option()
!$auth && $env_var_name !== "" && $env_value !== false && $env_value !== "" && $constant_name !== "" && !defined()67–83getenv(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), defined(), get_option()
!$auth && $env_var_name !== "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== ""73–95getenv(), defined(), constant(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), get_option()
2 further outcomes, up to 115 instructions
!$auth && $env_var_name !== "" && $env_value !== false && $env_value !== "" && $constant_name !== "" && defined()73–91getenv(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), defined(), constant(), get_option()
!$auth && $env_var_name !== "" && $env_value !== false && $env_value !== "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== ""97–115getenv(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), defined(), constant(), wp_connectors_parse_application_password_credentials(), __(), esc_html(), sprintf(), _doing_it_wrong(), get_option()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13233–11522
8.513233–11522
8.413233–11522
8.313233–11522
8.213233–11522
8.113233–115222 fewer instructions than PHP 7.4
7.413433–11722

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 5

Used by · 1

Source code

function wp_connectors_get_application_password_credentials( array $auth ): array {	// Check environment variable first.	$env_var_name = $auth['env_var_name'] ?? '';	if ( '' !== $env_var_name ) {		$env_value = getenv( $env_var_name );		if ( false !== $env_value && '' !== $env_value ) {			$credentials = wp_connectors_parse_application_password_credentials( $env_value );			if ( '' !== $credentials['username'] && '' !== $credentials['password'] ) {				$credentials['source'] = 'env';				return $credentials;			} 			_doing_it_wrong(				__FUNCTION__,				sprintf(					/* translators: %s: Environment variable name. */					__( 'The %s environment variable must contain application password credentials in "username:password" format.' ),					esc_html( $env_var_name )				),				'7.1.0'			);		}	} 	// Check PHP constant.	$constant_name = $auth['constant_name'] ?? '';	if ( '' !== $constant_name && defined( $constant_name ) ) {		$const_value = constant( $constant_name );		if ( is_string( $const_value ) && '' !== $const_value ) {			$credentials = wp_connectors_parse_application_password_credentials( $const_value );			if ( '' !== $credentials['username'] && '' !== $credentials['password'] ) {				$credentials['source'] = 'constant';				return $credentials;			} 			_doing_it_wrong(				__FUNCTION__,				sprintf(					/* translators: %s: PHP constant name. */					__( 'The %s constant must contain application password credentials in "username:password" format.' ),					esc_html( $constant_name )				),				'7.1.0'			);		}	} 	// Check database.	$stored   = get_option( $auth['setting_name'] ?? '', array() );	$username = is_array( $stored ) && isset( $stored['username'] ) && is_string( $stored['username'] ) ? $stored['username'] : '';	$password = is_array( $stored ) && isset( $stored['password'] ) && is_string( $stored['password'] ) ? $stored['password'] : ''; 	return array(		'username' => $username,		'password' => $password,		'source'   => '' !== $username && '' !== $password ? 'database' : 'none',	);}

Changelog

Introduced in 7.1.0.

Signature, return type and hooks compared across 1 parsed release.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/connectors.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.