wp_connectors_get_application_password_credentials( array $auth ): array{username:
- Since
- 7.1.0
- Source
wp-includes/connectors.php:522
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
- Scaling
- Constant
- Instructions
- 33–115
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 132.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
do_action()one call below wp_connectors_get_application_password_credentials() - cacheobject cache
wp_cache_get()one call below wp_connectors_get_application_password_credentials() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
!$auth && $env_var_name === "" && $constant_name === "" | 33–50 | get_option() |
!$auth && $env_var_name === "" && $constant_name !== "" && !defined() | 37–54 | defined(), get_option() |
!$auth && $env_var_name === "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== "" | 37–38 | defined(), constant(), wp_connectors_parse_application_password_credentials() |
!$auth && $env_var_name !== "" && $constant_name === "" | 39–58 | getenv(), get_option() |
!$auth && $env_var_name === "" && $constant_name !== "" && defined() | 43–62 | defined(), constant(), get_option() |
!$auth && $env_var_name !== "" && $constant_name !== "" && !defined() | 43–62 | getenv(), defined(), get_option() |
!$auth && $env_var_name !== "" && $constant_name !== "" && defined() && is_string($const_value) && $const_value !== "" | 43–46 | getenv(), defined(), constant(), wp_connectors_parse_application_password_credentials() |
!$auth && $env_var_name !== "" && $constant_name !== "" && defined() | 49–70 | getenv(), defined(), constant(), get_option() |
!$auth && $env_var_name !== "" && $env_value !== false && $env_value !== "" && $constant_name === "" | 63–79 | getenv(), 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–87 | defined(), 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–83 | getenv(), 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–95 | getenv(), 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–91 | getenv(), 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–115 | getenv(), 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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 132 | 33–115 | 22 | |
| 8.5 | 132 | 33–115 | 22 | |
| 8.4 | 132 | 33–115 | 22 | |
| 8.3 | 132 | 33–115 | 22 | |
| 8.2 | 132 | 33–115 | 22 | |
| 8.1 | 132 | 33–115 | 22 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 134 | 33–117 | 22 |
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
- wp_connectors_parse_application_password_credentials()Parses a `username:password` credentials string.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- get_option()Retrieves an option value based on an option name.
Used by · 1
- _wp_connectors_get_connector_script_module_data()Exposes connector settings to the connectors-wp-admin script module.
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.