From 555970c95096e24fa1c555729763d75e1920dc81 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 7 Mar 2012 03:41:56 +0000 Subject: [PATCH] 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 --- wp-includes/pluggable.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 08623f5e82..b9764f173a 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1310,6 +1310,10 @@ if ( !function_exists('wp_salt') ) : function wp_salt( $scheme = 'auth' ) { 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; if ( null === $duplicated_keys ) { $duplicated_keys = array( 'put your unique phrase here' => true ); @@ -1355,7 +1359,8 @@ function wp_salt( $scheme = 'auth' ) { $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;