WP_Recovery_Mode_Cookie_Service::recovery_mode_hash( string $data ): string|false
- Since
- 5.2.0
- Source
wp-includes/class-wp-recovery-mode-cookie-service.php:200
wp_hash() specific to Recovery Mode.Description
We cannot use wp_hash() because it is defined in pluggable.php which is not loaded until after plugins are loaded, which is too late to verify the recovery mode cookie.
This tries to use the AUTH salts first, but if they aren't valid specific salts will be generated and stored.
Compatibility
- WordPress
- since 5.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$datastring- Data to hash.
Return value
string|false- The hashed $data, or false on failure.
Performance profile
How much work a call to WP_Recovery_Mode_Cookie_Service::recovery_mode_hash() 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
- 32–83
- Plugin surface
- None
- Called by
- 2
Reads stored settings via get_site_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 87.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionnetwork option
get_site_option()called directly - hookthird-party callbacks
apply_filters()one call below WP_Recovery_Mode_Cookie_Service::recovery_mode_hash()
Further down the call graph this can also reach cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Recovery_Mode_Cookie_Service::recovery_mode_hash() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 32–43 | __(), put your unique phrase here(), get_site_option(), get_site_option(), hash_hmac() |
!$default_keys | 33–40 | __(), put your unique phrase here(), get_site_option(), hash_hmac() |
defined('AUTH_KEY') && !$default_keys && defined('AUTH_SALT') && $auth_key !== false | 37 | __(), put your unique phrase here(), hash_hmac() |
| always | 47–63 | __(), put your unique phrase here(), get_site_option(), get_site_option(), function_exists(), wp_generate_password(), update_site_option(), hash_hmac() |
| always | 47–63 | __(), put your unique phrase here(), get_site_option(), function_exists(), wp_generate_password(), update_site_option(), get_site_option(), hash_hmac() |
!$default_keys | 48–60 | __(), put your unique phrase here(), get_site_option(), function_exists(), wp_generate_password(), update_site_option(), hash_hmac() |
| always | 62–83 | __(), put your unique phrase here(), get_site_option(), function_exists(), wp_generate_password(), update_site_option(), get_site_option(), function_exists(), wp_generate_password(), update_site_option(), hash_hmac() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 87 | 32–83 | 9 | |
| 8.5 | 87 | 32–83 | 9 | |
| 8.4 | 87 | 32–83 | 9 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 93 | 32–89 | 9 | |
| 8.2 | 93 | 32–89 | 9 | |
| 8.1 | 93 | 32–89 | 9 | |
| 7.4 | 93 | 32–89 | 9 |
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 · 4
- __()Retrieves the translation of $text.
- get_site_option()Retrieve an option value for the current network based on name of option.
- wp_generate_password()Generates a random password drawn from the defined set of characters.
- update_site_option()Updates the value of an option that was already added for the current network.
Used by · 2
- WP_Recovery_Mode_Cookie_Service::generate_cookie()Generates the recovery mode cookie value.
- WP_Recovery_Mode_Cookie_Service::validate_cookie()Validates the recovery mode cookie.
Source code
private function recovery_mode_hash( $data ) { $default_keys = array_unique( array( 'put your unique phrase here', /* * translators: This string should only be translated if wp-config-sample.php is localized. * You can check the localized release package or * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php */ __( 'put your unique phrase here' ), ) ); if ( ! defined( 'AUTH_KEY' ) || in_array( AUTH_KEY, $default_keys, true ) ) { $auth_key = get_site_option( 'recovery_mode_auth_key' ); if ( ! $auth_key ) { if ( ! function_exists( 'wp_generate_password' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } $auth_key = wp_generate_password( 64, true, true ); update_site_option( 'recovery_mode_auth_key', $auth_key ); } } else { $auth_key = AUTH_KEY; } if ( ! defined( 'AUTH_SALT' ) || in_array( AUTH_SALT, $default_keys, true ) || AUTH_SALT === $auth_key ) { $auth_salt = get_site_option( 'recovery_mode_auth_salt' ); if ( ! $auth_salt ) { if ( ! function_exists( 'wp_generate_password' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } $auth_salt = wp_generate_password( 64, true, true ); update_site_option( 'recovery_mode_auth_salt', $auth_salt ); } } else { $auth_salt = AUTH_SALT; } $secret = $auth_key . $auth_salt; return hash_hmac( 'sha1', $data, $secret ); }Changelog
Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/class-wp-recovery-mode-cookie-service.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.