wp_salt( string $scheme = 'auth' ): string
- Since
- 2.5.0
- Source
wp-includes/pluggable.php:2581
Description
Salts are created using secret keys. Secret keys are located in two places: in the database and in the wp-config.php file. The secret key in the database is randomly generated and will be appended to the secret keys in wp-config.php.
The secret keys in wp-config.php should be updated to strong, random keys to maximize security. Below is an example of how the secret key constants are defined.
Do not paste this example directly into wp-config.php. Instead, have a https://api.wordpress.org/secret-key/1.1/salt/ secret key created just for you.
define('AUTH_KEY', ' Xakm<o xQy rw4EMsLKM-?!T+,PFF})H4lzcW57AF0U@N@< >M%G4Yt>fz]MON');
define('SECURE_AUTH_KEY', 'LzJ}op]mr|6+![P}Ak:uNdJCJZd>(Hx.-Mh#Tz)pCIU#uGEnfFz|f ;;eU%/U^O~');
define('LOGGED_IN_KEY', '|i|Ux9<p-h$aFf(qnT:sDO:D1P^wZ$$/Ra@miTJi9G;ddp_<q}6H1)o|a +&JCM');
define('NONCE_KEY', '%:R{[P|,s.KuMltH5}cI;/k<Gx~j!f0I)m_sIyu+&NJZ)-iO>z7X>QYR0Z_XnZ@|');
define('AUTH_SALT', 'eZyT)-Naw]F8CwA*VaW#q*|.)g@o}||wf~@C-YSt}(dh_r6EbI#A,y|nU2{B#JBW');
define('SECURE_AUTH_SALT', '!=oLUTXh,QW=H }L|9/^4-3 STz},T(w}W<I.JjPi)<Bmf1v,HpGe}T1:Xt7n');
define('LOGGED_IN_SALT', '+XSqHc;@Q*K_b|Z?NC[3H!!EONbh.n<+=uKR:>*c(ug~EJBf#8u#R{mUEZrozmm');
define('NONCE_SALT', 'hGXHhD>SLWVfg1(1(N{;.V!MoE(SfbA_ksP@&+AycHcAV$+?@3q+rxV{%^VyKT'); Salting passwords helps against tools which has stored hashed values of common dictionary strings. The added values makes it harder to crack.
Compatibility
- WordPress
- since 2.5.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
$schemestringoptional- Authentication scheme (auth, secure_auth, logged_in, nonce).Default:
'auth'
Return value
string- Salt value
Performance profile
How much work a call to wp_salt() 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
- 12–97
- Plugin surface
- 1 hook
- Called by
- 1
Reads stored settings via get_site_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 213.
Third-party callbacks on 'salt' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionnetwork option
get_site_option()called directly
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 · 16 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_salt() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12–55 | apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && $scheme | 40–60 | wp_prime_site_option_caches(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme && $values | 42–61 | hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && $scheme | 45–66 | __(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && !$scheme && $values | 47–66 | wp_prime_site_option_caches(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme | 49–68 | get_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && $scheme | 50–71 | __(), wp_prime_site_option_caches(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && !$scheme && $values | 52–72 | __(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && !$scheme | 54–73 | wp_prime_site_option_caches(), get_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && !$scheme && $values | 57–77 | __(), wp_prime_site_option_caches(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && !$scheme | 59–79 | __(), get_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme && !$values | 62–81 | get_site_option(), wp_generate_password(), update_site_option(), hash_hmac(), apply_filters() |
4 further outcomes, up to 97 instructions
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && !$scheme | 64–84 | __(), wp_prime_site_option_caches(), get_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && !$scheme && !$values | 67–86 | wp_prime_site_option_caches(), get_site_option(), wp_generate_password(), update_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && !$scheme && !$values | 72–92 | __(), get_site_option(), wp_generate_password(), update_site_option(), hash_hmac(), apply_filters() |
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && !$scheme && !$values | 77–97 | __(), wp_prime_site_option_caches(), get_site_option(), wp_generate_password(), update_site_option(), hash_hmac(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 213 instructions, 12–97 executed per call, 31 branches. The work does not change between versions.
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.
Hooks and filters fired · 2
2 hooks fire while wp_salt() runs, in this order:
Uses · 6
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- wp_prime_site_option_caches()Primes specific network options for the current network into the cache with a single database query.
- 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 · 1
- wp_hash()Gets the hash of the given string.
Source code
function wp_salt( $scheme = 'auth' ) { static $cached_salts = array(); if ( isset( $cached_salts[ $scheme ] ) ) { /** * Filters the WordPress salt. * * @since 2.5.0 * * @param string $cached_salt Cached salt for the given scheme. * @param string $scheme Authentication scheme. Values include 'auth', * 'secure_auth', 'logged_in', and 'nonce'. */ return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); } static $duplicated_keys; if ( null === $duplicated_keys ) { $duplicated_keys = array(); foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { foreach ( array( 'KEY', 'SALT' ) as $second ) { if ( ! defined( "{$first}_{$second}" ) ) { continue; } $value = constant( "{$first}_{$second}" ); $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); } } $duplicated_keys['put your unique phrase here'] = true; /* * 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 */ $duplicated_keys[ __( 'put your unique phrase here' ) ] = true; } /* * Determine which options to prime. * * If the salt keys are undefined, use a duplicate value or the * default `put your unique phrase here` value the salt will be * generated via `wp_generate_password()` and stored as a site * option. These options will be primed to avoid repeated * database requests for undefined salts. */ $options_to_prime = array(); foreach ( array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) as $key ) { foreach ( array( 'key', 'salt' ) as $second ) { $const = strtoupper( "{$key}_{$second}" ); if ( ! defined( $const ) || true === $duplicated_keys[ constant( $const ) ] ) { $options_to_prime[] = "{$key}_{$second}"; } } } if ( ! empty( $options_to_prime ) ) { /* * Also prime `secret_key` used for undefined salting schemes. * * If the scheme is unknown, the default value for `secret_key` will be * used too for the salt. This should rarely happen, so the option is only * primed if other salts are undefined. * * At this point of execution it is known that a database call will be made * to prime salts, so the `secret_key` option can be primed regardless of the * constants status. */ $options_to_prime[] = 'secret_key'; wp_prime_site_option_caches( $options_to_prime ); } $values = array( 'key' => '', 'salt' => '', ); if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) { $values['key'] = SECRET_KEY;Changelog
Introduced in 2.5.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 7.0.4 tag, from
src/wp-includes/pluggable.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.