apply_filters( ‘nonce_user_logged_out’, int $uid, string|int $action )

Filters whether the user who generated the nonce is logged out.

Parameters

$uidint
ID of the nonce-owning user.
$actionstring|int
The nonce action, or -1 if none was provided.

Source

$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );

Changelog

VersionDescription
3.5.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    /**
     * Custom function to modify the nonce value for logged-out users.
     *
     * @param int    $uid    The user ID (0 for logged-out users).
     * @param string $action The nonce action.
     *
     * @return int The modified user ID.
     */
    function wpdocs_modify_nonce_for_logged_out_users( $uid, $action ) {
        // Check if the user is logged out (uid = 0) and the specific nonce action.
        if ( 0 === $uid 0 && 'my_custom_action' === $action ) {
            // Generate a modified nonce for logged-out users.
            $uid = 999; // Example: use a specific user ID for logged-out users.
        }
    
        return $uid;
    }
    add_filter( 'nonce_user_logged_out', 'wpdocs_modify_nonce_for_logged_out_users', 10, 2 );

You must log in before being able to contribute a note or feedback.