Reduce nonce lifespan

Yes, using that filter will affect the lifespan of all nonces created after this filter is added, and while it remains in-place. So your best bet is to add it, create the nonce, remove it:

function my_nonce_lifetime() {
    return 600; // 10 minutes
}
add_filter( 'nonce_life', 'my_nonce_lifetime' );
$nonce = wp_create_nonce('wp_rest');
remove_filter( 'nonce_life', 'my_nonce_lifetime' );

Leave a Comment