Skip to content

Instantly share code, notes, and snippets.

@Magnacarter
Created December 18, 2014 23:27
Show Gist options
  • Save Magnacarter/e41ecbbd608a257f479b to your computer and use it in GitHub Desktop.
Save Magnacarter/e41ecbbd608a257f479b to your computer and use it in GitHub Desktop.
General registration form w/ hidden nonce field for WordPress
<?php
/**
*
*General registration form
*
*
*/
?>
<form method="post">
<p>
<label for="user_login">Username</label>
<input type="text" name="user_login" id="user_login" placeholder="Username" required>
</p>
<p>
<label for="user_pass">Password</label>
<input type="text" name="user_pass" id="user_pass" minlength="12" placeholder="Password" autocomplete="off" required>
</p>
<p>
<label for="user_pass_confirm">Confirm Password</label>
<input type="text" name="user_pass_confirm" id="user_pass_confirm" minlength="12" placeholder="Confirm Password" autocomplete="off" required>
</p>
<p>
<label for="first_name">Name</label>
<input type="text" name="first_name" id="first_name" placeholder="First" required>
<input type="text" name="last_name" id="last_name" placeholder="Last" required>
</p>
<p>
<label for="user_email">Email Address</label>
<input type="text" name="user_email" id="user_email" placeholder="Email Address" required>
</p>
<!-- Create a unique token 10 charactors long. -->
<?php $registration_token = strtolower( wp_generate_password( 10, false, false ) ) ?>
<!-- Store that token in the hidden value field to be verified when the POST isset. -->
<input type="hidden" name="registration_token" value="<?php echo esc_attr( $registration_token ) ?>">
<!-- Name the nonce field action and name. Here we concatonate the action w/ the randomly generated pw from above. -->
<?php wp_nonce_field( 'user_registration-' . $registration_token, 'registration_nonce' ) ?>
<p>
<button type="submit" id="submit-registration">Register</button>
</p>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment