DEV Community

Discussion on: I'm an expert in WordPress Development, Ask Me Anything!

jjjjcccjjf profile image
endan • Edited on

If you can give one lifehack in developing Wordpress applications what would it be?

gelform profile image
Corey Maass

Not the OP, but I'll jump in. Learn about using nonces with postbacks. It's not overly complicated, but it took me a while to understand the pattern. Once I understood this cycle, WordPress development (writing code) became so much clearer.

  1. Create an html form, that includes wp_nonce_field(). Now your form includes a string that's unique to that form and will be unique to post requests submitted by that form.

  2. In a plugin or in functions.php, add an init action that checks for post requests and uses wp_verify_nonce to check for the nonce. Now you know that form was submitted.

  3. Process the form data however you want, then use wp_redirect with the _wp_http_referer created by wp_nonce_field to send the user back to the form.

I now use this pattern everywhere in WordPress.