wp_create_nonce
Creates a cryptographic token tied to a specific action, user, user session, and window of time.
Description
(string) wp_create_nonce( (int) $action = -1 );
Returns (string)
The token.
Parameters (1)
- 0. $action — Optional. (int) =>
-1
- Scalar value to add context to the nonce.
Usage
if ( !function_exists( 'wp_create_nonce' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } // Scalar value to add context to the nonce. $action = -1; // NOTICE! Understand what this does before running. $result = wp_create_nonce($action);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/pluggable.php
- function wp_create_nonce($action = -1) {
- $user = wp_get_current_user();
- $uid = (int) $user->ID;
- if ( ! $uid ) {
- /** This filter is documented in wp-includes/pluggable.php */
- $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
- }
- $token = wp_get_session_token();
- $i = wp_nonce_tick();
- return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
- }