Filter hook 'salt'

in WP Core File wp-includes/pluggable.php at line 2592

View Source

salt

Filter Hook
Description
Filters the WordPress salt.

Hook Information

File Location wp-includes/pluggable.php View on GitHub
Hook Type Filter
Line Number 2592

Hook Parameters

Type Name Description
string $cached_salt Cached salt for the given scheme.
string $scheme Authentication scheme. Values include 'auth', 'secure_auth', 'logged_in', and 'nonce'. return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme ); } static $duplicated_keys; if ( null === $duplicated_keys ) { $duplicated_keys = array(); foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) { foreach ( array( 'KEY', 'SALT' ) as $second ) { if ( ! defined( "{$first}_{$second}" ) ) { continue; } $value = constant( "{$first}_{$second}" ); $duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] ); } } $duplicated_keys['put your unique phrase here'] = true; /* translators: This string should only be translated if wp-config-sample.php is localized. You can check the localized release package or https://i18n.svn.wordpress.org//branches//dist/wp-config-sample.php $duplicated_keys[ __( 'put your unique phrase here' ) ] = true; } /* Determine which options to prime. If the salt keys are undefined, use a duplicate value or the default `put your unique phrase here` value the salt will be generated via `wp_generate_password()` and stored as a site option. These options will be primed to avoid repeated database requests for undefined salts. $options_to_prime = array(); foreach ( array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) as $key ) { foreach ( array( 'key', 'salt' ) as $second ) { $const = strtoupper( "{$key}_{$second}" ); if ( ! defined( $const ) || true === $duplicated_keys[ constant( $const ) ] ) { $options_to_prime[] = "{$key}_{$second}"; } } } if ( ! empty( $options_to_prime ) ) { /* Also prime `secret_key` used for undefined salting schemes. If the scheme is unknown, the default value for `secret_key` will be used too for the salt. This should rarely happen, so the option is only primed if other salts are undefined. At this point of execution it is known that a database call will be made to prime salts, so the `secret_key` option can be primed regardless of the constants status.

Usage Examples

Basic Usage
<?php
// Hook into salt
add_filter('salt', 'my_custom_filter', 10, 2);

function my_custom_filter($cached_salt, $scheme) {
    // Your custom filtering logic here
    return $cached_salt;
}

Source Code Context

wp-includes/pluggable.php:2592 - How this hook is used in WordPress core
<?php
2587  		}
2588  
2589  		$cached_salts[ $scheme ] = $values['key'] . $values['salt'];
2590  
2591  		/** This filter is documented in wp-includes/pluggable.php */
2592  		return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
2593  	}
2594  endif;
2595  
2596  if ( ! function_exists( 'wp_hash' ) ) :
2597  	/**

PHP Documentation

<?php
/**
			 * Filters the WordPress salt.
			 *
			 * @since 2.5.0
			 *
			 * @param string $cached_salt Cached salt for the given scheme.
			 * @param string $scheme      Authentication scheme. Values include 'auth',
			 *                            'secure_auth', 'logged_in', and 'nonce'.
			 */
			return apply_filters( 'salt', $cached_salts[ $scheme ], $scheme );
		}

		static $duplicated_keys;
		if ( null === $duplicated_keys ) {
			$duplicated_keys = array();

			foreach ( array( 'AUTH', 'SECURE_AUTH', 'LOGGED_IN', 'NONCE', 'SECRET' ) as $first ) {
				foreach ( array( 'KEY', 'SALT' ) as $second ) {
					if ( ! defined( "{$first}_{$second}" ) ) {
						continue;
					}
					$value                     = constant( "{$first}_{$second}" );
					$duplicated_keys[ $value ] = isset( $duplicated_keys[ $value ] );
				}
			}

			$duplicated_keys['put your unique phrase here'] = true;

			/*
			 * translators: This string should only be translated if wp-config-sample.php is localized.
			 * You can check the localized release package or
			 * https://i18n.svn.wordpress.org/<locale code>/branches/<wp version>/dist/wp-config-sample.php
			 */
			$duplicated_keys[ __( 'put your unique phrase here' ) ] = true;
		}

		/*
		 * Determine which options to prime.
		 *
		 * If the salt keys are undefined, use a duplicate value or the
		 * default `put your unique phrase here` value the salt will be
		 * generated via `wp_generate_password()` and stored as a site
		 * option. These options will be primed to avoid repeated
		 * database requests for undefined salts.
		 */
		$options_to_prime = array();
		foreach ( array( 'auth', 'secure_auth', 'logged_in', 'nonce' ) as $key ) {
			foreach ( array( 'key', 'salt' ) as $second ) {
				$const = strtoupper( "{$key}_{$second}" );
				if ( ! defined( $const ) || true === $duplicated_keys[ constant( $const ) ] ) {
					$options_to_prime[] = "{$key}_{$second}";
				}
			}
		}

		if ( ! empty( $options_to_prime ) ) {
			/*
			 * Also prime `secret_key` used for undefined salting schemes.
			 *
			 * If the scheme is unknown, the default value for `secret_key` will be
			 * used too for the salt. This should rarely happen, so the option is only
			 * primed if other salts are undefined.
			 *
			 * At this point of execution it is known that a database call will be made
			 * to prime salts, so the `secret_key` option can be primed regardless of the
			 * constants status.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/pluggable.php
Related Hooks

Related hooks will be displayed here in future updates.