I test a solution for separate registration for different roles and it works very well. But the validation part/function (see bellow) on errors reloads/reuses the generic registration link and not the role specific link, e.g. http://example.com/wp-login.php?action=register
instead of http://example.com/wp-login.php?action=register&role=seller
. How to avoid this?
The validation function:
add_action('register_post','my_user_fields_validation',10,3);
function my_user_fields_validation($login, $email, $errors) {
global $firstname, $lastname;
//get the role to check
if (isset($_POST['role'])){
$user_type = $_POST['role'];
}
//check the fields according to the role
if (isset($user_type) && $user_type == "seller"){
//check sellers fields
if ($_POST['business_name'] == '') {
$errors->add('empty_business_name', "<strong>ERROR</strong>: Please Enter in a Business name");
}
if ($_POST['business_address'] == '') {
$errors->add('empty_business_address', "<strong>ERROR</strong>: Please Enter in Business address");
}
}
if (isset($user_type) && $user_type == "buyer"){
//check buyers fields
if ($_POST['buyer_name'] == '') {
$errors->add('empty_buyer_name', "<strong>ERROR</strong>: Please Enter in a Buyer name");
}
}
}
You can either user session or cookies to setup the user for the desired role e.g: