How to Assign Different User Role per Registration Forms in WordPress - ProfilePress

How to Assign Different User Role per Registration Forms in WordPress

Prior to Profilepress version 1.9, defining a user role that registering users will be assigned — aside the one set in WordPress general settings — was only possible via pp_after_registration action hook like so:

add_action( 'ppress_after_registration', 'pp_insert_user_role', 10, 3 );
 
function pp_insert_user_role( $form_id, $user_data, $user_id ) {
 
	$a = get_user_by( 'id', $user_id );
 
	// clear existing role if exist.
	$a->set_role( '' );
 
	// add the roles
	$a->add_role( 'student' );
}

In version 1.9, we introduced the option for a site administrator/owner to select the role that will be assigned to users on successful completion of their account registration via a ProfilePress powered registration form. As a result, you can create a different WordPress registration form that will assign different roles to users.

To set the user role; go to the form edit screen, at the bottom of the page, select the user as shown in the image below.

Select user role per registration form

Finally, save the form.

Put it to test although we are certain it will work as expected.

You could also allow users to select the role they will be assigned on the registration form. See this post for the tutorial.