Internally cache return values of wp_salt(). Always run the filter. Big performance gains on a pageload that generates hundreds of nonces. see #19599.

git-svn-id: https://develop.svn.wordpress.org/trunk@20135 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-03-07 03:41:56 +00:00
parent 98715e56d9
commit 555970c950
1 changed files with 6 additions and 1 deletions

View File

@ -1310,6 +1310,10 @@ if ( !function_exists('wp_salt') ) :
function wp_salt( $scheme = 'auth' ) { function wp_salt( $scheme = 'auth' ) {
global $wp_secret_key_default; // This is set for localized builds for versions > 3.4.0. global $wp_secret_key_default; // This is set for localized builds for versions > 3.4.0.
static $cached_salts = array();
if ( isset( $cached_salts[ $scheme ] ) )
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
static $duplicated_keys; static $duplicated_keys;
if ( null === $duplicated_keys ) { if ( null === $duplicated_keys ) {
$duplicated_keys = array( 'put your unique phrase here' => true ); $duplicated_keys = array( 'put your unique phrase here' => true );
@ -1355,7 +1359,8 @@ function wp_salt( $scheme = 'auth' ) {
$salt = hash_hmac( 'md5', $scheme, $key ); $salt = hash_hmac( 'md5', $scheme, $key );
} }
return apply_filters('salt', $key . $salt, $scheme); $cached_salts[ $scheme ] = $key . $salt;
return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
} }
endif; endif;