· 7 years ago · Aug 20, 2018, 10:41 PM
1function wp_salt( $scheme = 'auth' ) {
2 static $cached_salts = array();
3 if ( isset( $cached_salts[ $scheme ] ) ) {
4 /**
5 * Filters the WordPress salt.
6 *
7 * @since 2.5.0
8 *
9 * @param string $cached_salt Cached salt for the given scheme.
10 * @param string $scheme Authentication scheme. Values include 'auth',
11 * 'secure_auth', 'logged_in', and 'nonce'.
12 */
13 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
14 }
15 static $duplicated_keys;
16 if ( null === $duplicated_keys ) {
17 $duplicated_keys = array( 'put your unique phrase here' => true );
18 foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) {
19 foreach ( array( 'KEY', 'SALT' ) as $second ) {
20 if ( ! defined( "{$first}_{$second}" ) ) {
21 continue;
22 }
23 $value = constant( "{$first}_{$second}" );
24 $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] );
25 }
26 }
27 }
28 $values = array(
29 'key' => '',
30 'salt' => '',
31 );
32 if ( defined( 'SECRET_KEY' ) && SECRET_KEY && empty( $duplicated_keys[ SECRET_KEY ] ) ) {
33 $values['key'] = SECRET_KEY;
34 }
35 if ( 'auth' == $scheme && defined( 'SECRET_SALT' ) && SECRET_SALT && empty( $duplicated_keys[ SECRET_SALT ] ) ) {
36 $values['salt'] = SECRET_SALT;
37 }
38 if ( in_array( $scheme, array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) ) ) {
39 foreach ( array( 'key', 'salt' ) as $type ) {
40 $const = strtoupper( "{$scheme}_{$type}" );
41 if ( defined( $const ) && constant( $const ) && empty( $duplicated_keys[ constant( $const ) ] ) ) {
42 $values[ $type ] = constant( $const );
43 } elseif ( ! $values[ $type ] ) {
44 $values[ $type ] = get_site_option( "{$scheme}_{$type}" );
45 if ( ! $values[ $type ] ) {
46 $values[ $type ] = wp_generate_password( 64, true, true );
47 update_site_option( "{$scheme}_{$type}", $values[ $type ] );
48 }
49 }
50 }
51 } else {
52 if ( ! $values['key'] ) {
53 $values['key'] = get_site_option( 'secret_key' );
54 if ( ! $values['key'] ) {
55 $values['key'] = wp_generate_password( 64, true, true );
56 update_site_option( 'secret_key', $values['key'] );
57 }
58 }
59 $values['salt'] = hash_hmac( 'md5', $scheme, $values['key'] );
60 }
61 $cached_salts[ $scheme ] = $values['key'] . $values['salt'];
62 /** This filter is documented in wp-includes/pluggable.php */
63 return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
64 }