wppaste
WordPress

wp_salt( string $scheme = 'auth' ): string

Since
2.5.0
Source
wp-includes/pluggable.php:2585
Returns a salt to add to hashes.

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

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

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
12–97

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

Plugin surface
1 hook

Third-party callbacks on 'salt' run inside this call, and their cost is not bounded by anything here.

Called by
1

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

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionnetwork optionget_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.

WhenInstructionsCalls it makes
always12–55apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && $scheme40–60wp_prime_site_option_caches(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme && $values42–61hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && $scheme45–66__(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && !$scheme && $values47–66wp_prime_site_option_caches(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme49–68get_site_option(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && $scheme50–71__(), wp_prime_site_option_caches(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && !$scheme && $values52–72__(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && !empty($options_to_prime) && !$scheme54–73wp_prime_site_option_caches(), get_site_option(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys === null && !empty($options_to_prime) && !$scheme && $values57–77__(), wp_prime_site_option_caches(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys === null && empty($options_to_prime) && !$scheme59–79__(), get_site_option(), hash_hmac(), apply_filters()
!isset($cached_salts[$scheme]) && $duplicated_keys !== null && empty($options_to_prime) && !$scheme && !$values62–81get_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) && !$scheme64–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 && !$values67–86wp_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 && !$values72–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 && !$values77–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:

  1. apply_filters( salt )filterline 2597 (+12 into the body)

    Filters the WordPress salt.

  2. apply_filters( salt )filterline 2697 (+112 into the body)

    Filters the WordPress salt.

Uses · 6

Used by · 1

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.