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

  1. if ( !function_exists( 'wp_create_nonce' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // Scalar value to add context to the nonce. 
  5. $action = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_create_nonce($action); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/pluggable.php  
  1. function wp_create_nonce($action = -1) { 
  2. $user = wp_get_current_user(); 
  3. $uid = (int) $user->ID; 
  4. if ( ! $uid ) { 
  5. /** This filter is documented in wp-includes/pluggable.php */ 
  6. $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); 
  7.  
  8. $token = wp_get_session_token(); 
  9. $i = wp_nonce_tick(); 
  10.  
  11. return substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );