Nonce fail after second submit attempt

I am refactoring my plugin that resets the WordPress database tables back to their defaults and came across an issue.

The form submission itself works fine. However, after the first submit, and if you do not refresh the page and submit the form again, the nonce seems to fail. Perhaps there is someone that fully understands how nonces work as I am not sure what is causing this.

I have the necessary check for wp_nonce_field and check_admin_referer on the administration side.

As I can't post specific parts of the code, here is the link to the refactored (WIP) plugin:

https://github.com/chrisberthe/wordpress-database-reset/tree/refactoring

Topic nonce php forms Wordpress

Category Web


Not 100 % positive but my understanding is that a Nonce expire as soon as you use it. It can only be used for one transaction. So it seems to be logic that it expire after the first call.

You should probably return a new one with the response of your first validated request and replace it.

Hope this helps!

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.