From 20f416f28614c5029e48bd7a20b1208276c4d6e3 Mon Sep 17 00:00:00 2001 From: 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: http://svn.automattic.com/wordpress/trunk@20135 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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;