Skip to content

Instantly share code, notes, and snippets.

@theodorocaliari
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theodorocaliari/8fa631c0c0ca2f084f50 to your computer and use it in GitHub Desktop.
Save theodorocaliari/8fa631c0c0ca2f084f50 to your computer and use it in GitHub Desktop.
<?php
// Add Password, Repeat Password and Are You Human fields to WordPress registration form
// http://wp.me/p1Ehkq-gn
add_action( 'register_form', 'ts_show_extra_register_fields' );
function ts_show_extra_register_fields(){
?>
<p>
<label for="password">Password<br/>
<input id="password" class="input" type="password" tabindex="30" size="25" value="" name="password" />
</label>
</p>
<p>
<label for="repeat_password">Repeat password<br/>
<input id="repeat_password" class="input" type="password" tabindex="40" size="25" value="" name="repeat_password" />
</label>
</p>
<p>
<label for="are_you_human" style="font-size:11px">Sorry, but we must check if you are human. What is the name of website you are registering for?<br/>
<input id="are_you_human" class="input" type="text" tabindex="40" size="25" value="" name="are_you_human" />
</label>
</p>
<?php
}
// Check the form for errors
add_action( 'register_post', 'ts_check_extra_register_fields', 10, 3 );
function ts_check_extra_register_fields($login, $email, $errors) {
if ( $_POST['password'] !== $_POST['repeat_password'] ) {
$errors->add( 'passwords_not_matched', "<strong>ERROR</strong>: Passwords must match" );
}
if ( strlen( $_POST['password'] ) < 8 ) {
$errors->add( 'password_too_short', "<strong>ERROR</strong>: Passwords must be at least eight characters long" );
}
if ( $_POST['are_you_human'] !== get_bloginfo( 'name' ) ) {
$errors->add( 'not_human', "<strong>ERROR</strong>: Your name is Bot? James Bot? Check bellow the form, there's a Back to [sitename] link." );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment