WordPress user registration
WordPress has built in user registration functionality, however it is username or email address based and not brilliant visually.
Enable user registration via wordpress
Settings > General > Membership > Anyone can register
User register
https://yoursite.com/wp-admin
https://yoursite.com/wp-login.php?action=register
Adding a custom field to new user registration
Note – this will not work with BuddyPress, as BuddyPress overrides the default WP registration
This code not yet tested but should just work:
//******************************************************************
//******************************************************************
//********** NEW USER REGISTRATION ADD CUSTOM FORM FIELDS **********
//******************************************************************
//******************************************************************
function myplugin_register_form()
{
//die("WORKED");
//Handle form resubmission - get any fields previously submitted
$signup_code = ( isset( $_POST['signup_code'] ) ) ? $_POST['signup_code'] : '';
?>
<p>
<label for="signup_code">Signup Code<br />
<input type="text" name="signup_code" id="signup_code" class="input" value="<?php echo esc_attr( stripslashes( $signup_code ) ); ?>" size="25" /></label>
</p>
<?php
}
add_action('register_form', 'myplugin_register_form');
//******************************************************************
//******************************************************************
//********** NEW USER REGISTRATION CHECK FIELDS SUBMITTED **********
//******************************************************************
//******************************************************************
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email)
{
if (!isset($_POST['signup_code']) || $_POST['signup_code'] !== 'ABC')
{
//Cause signup to fail
$errors->add( 'My_custom_error', '<strong>ERROR</strong>: Invalid Signup Code.' );
}
return $errors;
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.