wp_verify_nonce

The timeline below displays how wordpress function wp_verify_nonce has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Verifies that a correct security nonce was used with time limit.
 *
 * A nonce is valid for 24 hours (by default).
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce value that was used for verification, usually via a form field.
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
 *                   2 if the nonce is valid and generated between 12-24 hours ago.
 *                   False if the nonce is invalid.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filters whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int        $uid    ID of the nonce-owning user.
         * @param string|int $action The nonce action, or -1 if none was provided.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick($action);
    // Nonce generated 0-12 hours ago.
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago.
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    /**
     * Fires when nonce verification fails.
     *
     * @since 4.4.0
     *
     * @param string     $nonce  The invalid nonce.
     * @param string|int $action The nonce action.
     * @param WP_User    $user   The current user object.
     * @param string     $token  The user's session token.
     */
    do_action('wp_verify_nonce_failed', $nonce, $action, $user, $token);
    // Invalid nonce.
    return false;
}

WordPress Version: 5.4

/**
 * Verifies that a correct security nonce was used with time limit.
 *
 * A nonce is valid for 24 hours (by default).
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce value that was used for verification, usually via a form field.
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return int|false 1 if the nonce is valid and generated between 0-12 hours ago,
 *                   2 if the nonce is valid and generated between 12-24 hours ago.
 *                   False if the nonce is invalid.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filters whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago.
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago.
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    /**
     * Fires when nonce verification fails.
     *
     * @since 4.4.0
     *
     * @param string     $nonce  The invalid nonce.
     * @param string|int $action The nonce action.
     * @param WP_User    $user   The current user object.
     * @param string     $token  The user's session token.
     */
    do_action('wp_verify_nonce_failed', $nonce, $action, $user, $token);
    // Invalid nonce.
    return false;
}

WordPress Version: 5.3

/**
 * Verifies that a correct security nonce was used with time limit.
 *
 * A nonce is valid for 24 hours (by default).
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce value that was used for verification, usually via a form field.
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
 *                   0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filters whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    /**
     * Fires when nonce verification fails.
     *
     * @since 4.4.0
     *
     * @param string     $nonce  The invalid nonce.
     * @param string|int $action The nonce action.
     * @param WP_User    $user   The current user object.
     * @param string     $token  The user's session token.
     */
    do_action('wp_verify_nonce_failed', $nonce, $action, $user, $token);
    // Invalid nonce
    return false;
}

WordPress Version: 4.6

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
 *                   0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filters whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    /**
     * Fires when nonce verification fails.
     *
     * @since 4.4.0
     *
     * @param string     $nonce  The invalid nonce.
     * @param string|int $action The nonce action.
     * @param WP_User    $user   The current user object.
     * @param string     $token  The user's session token.
     */
    do_action('wp_verify_nonce_failed', $nonce, $action, $user, $token);
    // Invalid nonce
    return false;
}

WordPress Version: 4.4

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
 *                   0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    /**
     * Fires when nonce verification fails.
     *
     * @since 4.4.0
     *
     * @param string     $nonce  The invalid nonce.
     * @param string|int $action The nonce action.
     * @param WP_User    $user   The current user object.
     * @param string     $token  The user's session token.
     */
    do_action('wp_verify_nonce_failed', $nonce, $action, $user, $token);
    // Invalid nonce
    return false;
}

WordPress Version: 4.2

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
 *                   0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 4.1

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string     $nonce  Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $nonce = (string) $nonce;
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 4.0

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    if (empty($nonce)) {
        return false;
    }
    $token = wp_get_session_token();
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid . '|' . $token, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .10

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 3.9

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        /**
         * Filter whether the user who generated the nonce is logged out.
         *
         * @since 3.5.0
         *
         * @param int    $uid    ID of the nonce-owning user.
         * @param string $action The nonce action.
         */
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .30

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 8.3

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .20

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 8.2

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .10

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 3.8

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .30

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 7.3

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .20

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 7.2

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: .10

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    $expected = substr(wp_hash($i . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    $expected = substr(wp_hash($i - 1 . '|' . $action . '|' . $uid, 'nonce'), -12, 10);
    if (hash_equals($expected, $nonce)) {
        return 2;
    }
    // Invalid nonce
    return false;
}

WordPress Version: 3.7

/**
 * Verify that correct nonce was used with time limit.
 *
 * The user is given an amount of time to use the token, so therefore, since the
 * UID and $action remain the same, the independent variable is the time.
 *
 * @since 2.0.3
 *
 * @param string $nonce Nonce that was used in the form to verify
 * @param string|int $action Should give context to what is taking place and be the same when nonce was created.
 * @return bool Whether the nonce check passed or failed.
 */
function wp_verify_nonce($nonce, $action = -1)
{
    $user = wp_get_current_user();
    $uid = (int) $user->ID;
    if (!$uid) {
        $uid = apply_filters('nonce_user_logged_out', $uid, $action);
    }
    $i = wp_nonce_tick();
    // Nonce generated 0-12 hours ago
    if (substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 1;
    }
    // Nonce generated 12-24 hours ago
    if (substr(wp_hash($i - 1 . $action . $uid, 'nonce'), -12, 10) === $nonce) {
        return 2;
    }
    // Invalid nonce
    return false;
}