Skip to content

Commit 74e03e3

Browse files
committed
Options, Meta APIs: Prime salts when stored in database.
For salts generated and stored in the database, use `wp_prime_site_option_caches()` within `wp_salt()` to prime the options in a single database query, down from up to nine database queries. The options are primed when the corresponding constant is either undefined or uses the default string `put your unique phrase here`. Props joemcgill, spacedmonkey, peterwilsoncc. Fixes #59871. git-svn-id: https://develop.svn.wordpress.org/trunk@58837 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 883146e commit 74e03e3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/wp-includes/pluggable.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,41 @@ function wp_salt( $scheme = 'auth' ) {
24682468
}
24692469
}
24702470

2471+
/*
2472+
* Determine which options to prime.
2473+
*
2474+
* If the salt keys are undefined, use a duplicate value or the
2475+
* default `put your unique phrase here` value the salt will be
2476+
* generated via `wp_generate_password()` and stored as a site
2477+
* option. These options will be primed to avoid repeated
2478+
* database requests for undefined salts.
2479+
*/
2480+
$options_to_prime = array();
2481+
foreach ( array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) as $key ) {
2482+
foreach ( array( 'key', 'salt' ) as $second ) {
2483+
$const = strtoupper( "{$key}_{$second}" );
2484+
if ( ! defined( $const ) || true === $duplicated_keys[ constant( $const ) ] ) {
2485+
$options_to_prime[] = "{$key}_{$second}";
2486+
}
2487+
}
2488+
}
2489+
2490+
if ( ! empty( $options_to_prime ) ) {
2491+
/*
2492+
* Also prime `secret_key` used for undefined salting schemes.
2493+
*
2494+
* If the scheme is unknown the default value for `secret_key` will be
2495+
* used to for the salt. This should rarely happen so the option is only
2496+
* primed if other salts are undefined.
2497+
*
2498+
* At this point of execution is is known that a database call will be made
2499+
* to prime salts so the `secret_key` option can be primed regardless of the
2500+
* constants status.
2501+
*/
2502+
$options_to_prime[] = 'secret_key';
2503+
wp_prime_site_option_caches( $options_to_prime );
2504+
}
2505+
24712506
$values = array(
24722507
'key' => '',
24732508
'salt' => '',

0 commit comments

Comments
 (0)