diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 0e9e0d4579..ae5355f9c6 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -2468,6 +2468,41 @@ if ( ! function_exists( 'wp_salt' ) ) : } } + /* + * 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 to for the salt. This should rarely happen so the option is only + * primed if other salts are undefined. + * + * At this point of execution is 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' => '',