Using nonce external of WP Admin

Nonces are not tied to the admin interface. This codex page explains them very well. Essentially, you add :

<?php wp_nonce_field('name_of_my_action', 'name_of_nonce_field'); ?>

in your form (this creates a hidden input field containing an one-time-use token). And where you’re doing the form processing you just check if the nonce is correct

if(!wp_verify_nonce($_POST['name_of_nonce_field'], 'name_of_my_action')){
  // no permissions
}

Leave a Comment