wp_connectors_sanitize_application_password_credentials( mixed $value, string $option = '' ): array{username:
- Since
- 7.1.0
- Source
wp-includes/connectors.php:641
Description
Credential fields that are missing or not strings keep their currently stored values, so partial updates cannot silently clear a stored secret.
A password matching the mask that _wp_connectors_rest_settings_dispatch() places in REST responses also keeps the stored password, so a masked settings response can be submitted back to the endpoint unchanged.
Pass an empty string to clear a field.
If the sanitized username is empty, both fields are discarded so partial credentials cannot leave an orphaned secret.
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
$valuemixed- The submitted setting value.
$optionstringoptional- The option name being sanitized. Passed explicitly by the registered sanitize callback; falls back to the current
sanitize_option_{$option}filter name when omitted.Default:''
Return value
array{username:- string, password: string} Sanitized credentials.
Performance profile
How much work a call to wp_connectors_sanitize_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
- Heavy
- Scaling
- Scales with input
- Instructions
- 22–40
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 66.
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
apply_filters()one call below wp_connectors_sanitize_application_password_credentials() - cacheobject cache
wp_cache_get()one call below wp_connectors_sanitize_application_password_credentials() - serializeserialisation
maybe_unserialize()one call below wp_connectors_sanitize_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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_connectors_sanitize_application_password_credentials() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$option !== "" | 22–34 | get_option() |
$option === "" | 28–40 | current_filter(), get_option() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 66 | 22–40 | 13 | |
| 8.5 | 66 | 22–40 | 13 | |
| 8.4 | 66 | 22–40 | 13 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 69 | 22–43 | 13 | |
| 8.2 | 69 | 22–43 | 13 | |
| 8.1 | 69 | 22–43 | 13 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 71 | 22–44 | 13 |
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 · 3
- current_filter()Retrieves the name of the current filter hook.
- get_option()Retrieves an option value based on an option name.
- sanitize_text_field()Sanitizes a string from user input or from the database.
Used by · 1
- _wp_register_default_connector_settings()Registers default connector settings.
Source code
function wp_connectors_sanitize_application_password_credentials( $value, string $option = '' ): array { if ( ! is_array( $value ) ) { $value = array(); } if ( '' === $option ) { $option = str_replace( 'sanitize_option_', '', (string) current_filter() ); } $stored = get_option( $option ); if ( ! is_array( $stored ) ) { $stored = array(); } $credentials = array(); foreach ( array( 'username', 'password' ) as $field ) { if ( isset( $value[ $field ] ) && is_string( $value[ $field ] ) ) { $credentials[ $field ] = sanitize_text_field( $value[ $field ] ); } else { $credentials[ $field ] = isset( $stored[ $field ] ) && is_string( $stored[ $field ] ) ? $stored[ $field ] : ''; } } // A masked password means a client resubmitted a masked REST response. if ( str_repeat( "\u{2022}", 16 ) === $credentials['password'] ) { $credentials['password'] = isset( $stored['password'] ) && is_string( $stored['password'] ) ? $stored['password'] : ''; } if ( '' === $credentials['username'] ) { return array( 'username' => '', 'password' => '', ); } return $credentials;}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.