We are developing one magazine website by using WordPress. So that I have to generate different types of user roles.. Users, Authors, Editors etc. For them to register I want to generate different types of users registration forms.
Please suggest me if there is available any plugin to satisfy my requirement..
Thanks in Advance
This can be easily achieved using the Multiple Registration Forms module from Profile Builder plugin.
It's shortcode based and allows you to set up multiple registration forms with different profile fields for different user roles.
Here's a step by step tutorial on how to set up multiple registration forms.
For creating different user roles, you can use a free membership plugin like Members. These two recommended plugins have been tested and play really well together.
I have faced the same issue, I have 2 roles types with different registration form fields ..this is how I achieved, Hope this might help:
First create 2 registration WordPress pages and create 2 different templates for each pages.
For template content add the forms content for each templates as per the need example:
<form action="" method="post">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="ti-user"></i></span>
<input type="text" class="form-control" name="username" placeholder="User name" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="ti-email"></i></span>
<input type="text" name="email" class="form-control" placeholder="Your email address" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="ti-unlock"></i></span>
<input type="password" name="password"class="form-control" placeholder="Choose a password" required>
</div>
</div>
<button class="btn btn-primary btn-block" type="submit" name="employeeregister">Sign up</button>
</form>
Similarly we can create other template, Then in function.php add the following code:
<?php
/** Validation Check*/
function registration_validation( $username, $password, $email) {
global $reg_errors;
$reg_errors = new WP_Error;
if ( empty( $username ) || empty( $password ) || empty( $email ) ) {
$reg_errors->add('field', 'Required form field is missing');
} else {
if ( 4 > strlen( $username ) ) {
$reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
}
if ( username_exists( $username ) ){
$reg_errors->add('user_name', 'Sorry, that username already exists!');
}
if ( 5 > strlen( $password ) ) {
$reg_errors->add( 'password', 'Password length must be greater than 5' );
}
if ( !is_email( $email ) ) {
$reg_errors->add( 'email_invalid', 'Email is not valid' );
}
if ( email_exists( $email ) ) {
$reg_errors->add( 'email', 'Email Already in use' );
}
}}
/** Registration in WP*/
function registration($username, $password, $email, $roletype) {
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'role' => $roletype,
);
$user = wp_insert_user( $userdata );
echo 'Registration complete.';
}
?>
Here we are adding two functions one validating the form submitted and other inserting the user in WordPress database.
Finally we would call the above functions from our template page and insert the user.
<?php if (isset($_POST['employeeregister'])) {
$getusername = sanitize_user( $_POST['username'] );
$getpassword = esc_attr( $_POST['password'] );
$getemail = $_POST['email'];
$gettype = 'employee';
registration_validation($getusername,$getpassword,$getemail);
if( is_wp_error( $reg_errors ) && ! empty( $reg_errors->errors ) ) {?>
<ul class="woocommerce-error" role="alert">
<?php
foreach ( $reg_errors->get_error_messages() as $error ) {
echo '<li>';
echo '<strong>ERROR</strong>: ';
echo $error . '<br/>';
echo '</li>';
}?>
</ul>
<?php }
if ( 1 > count( $reg_errors->get_error_messages() ) ) {
registration($getusername,$getpassword,$getemail,$gettype);
}} ?>
Now just link the role registration as per page created.
Thanks