wp_hash()
Gets hash of a given string.
A hash — it is a fixed-length string created from any data. Such a string is created in such a way that the probability of occurrence of different data with the same hash tends to zero, and restore data by their hash was as difficult as possible.
This is a pluggable function, and it can be replaced by a plugin. It means that this function is defined (works) only after all plugins are loaded (included), but before this moment this function has not defined. Therefore, you cannot call this and all functions depended on this function directly from a plugin code. They need to be called on plugins_loaded hook or later, for example on init hook.
Function replacement (override) — in a plugin you can create a function with the same name, then it replace this function.
No Hooks.
Return
String
. Hash of $data.
Usage
wp_hash( $data, $scheme );
- $data(string) (required)
- Plain text, a hash of which to create.
- $scheme(string)
Authentication scheme. The principle of hashing. This parameter is passed to wp_salt(), the result of which is then added to the hash. It may be:
- auth
- secure_auth
- logged_in
- nonce
Default: 'auth'
Examples
#1 Demonstration
echo wp_hash( 'wp-kama' ); //> af3393632a8bb769275e1e992cac39c4 // second call echo wp_hash( 'wp-kama' ); //> af3393632a8bb769275e1e992cac39c4 echo wp_hash( 'WP-KAMA' ); //> b919a9bc1a3f37892bd3dc150e67785a
Changelog
Since 2.0.3 | Introduced. |
wp_hash() wp hash code WP 6.1.1
function wp_hash( $data, $scheme = 'auth' ) { $salt = wp_salt( $scheme ); return hash_hmac( 'md5', $data, $salt ); }