Make WordPress Core

Changeset 58837


Ignore:
Timestamp:
07/31/2024 10:56:32 PM (3 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r58674 r58837  
    24672467                }
    24682468            }
     2469        }
     2470
     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 );
    24692504        }
    24702505
Note: See TracChangeset for help on using the changeset viewer.