A client recently contacted me searching for an easy way to automatically assign a specific role to a registering user based on the domain (i.e. gmail.com) of the user’s email address (i.e. email@example.com).
If the registering user’s email domain was a part of his organization, that user would be assigned to an “Employee” role. All other registering users would be assigned to the generic “Subscriber” role.
Fortunately, the registration form was powered by the Gravity Forms User Registration add-on which makes this super easy to accomplish.
In this tutorial, I will show you how to use multiple User Registration feeds to assign specific user roles dependent on the email domain of the registering user. Let’s get started!
You’ll need a few things to get started.
Ready to walk through each step?
- Step 1: Set up the registration form in Gravity Forms
- Step 2: Configure the form to create user accounts
- Step 3: Create a User Registration Feed for Each User Role
Step 1: Setting Up the Registration Form
First things first, we need to set up the form that will be used to register users for the site. To create a simple version of this form, please follow the directions found here. If you follow these instructions you’ll wind up with a form that looks like this:
Now that we have our basic registration form, we need to set up the form to create new user accounts.
Step 2: Configure the form to create user accounts
The User Registration Add-on allows us to create feeds that map the Registration Form fields to WordPress User fields. So you simply need to connect the correct WordPress labels with the values from your form.
At the bottom of the Registration Feed, you will see a section called “Additional Options.” In this section there is an option called “Registration Condition.” This is where the magic happens.
Check the “Enable” checkbox to enable this option. A new option will be displayed that allows you to specify a condition for this registration feed. This means that if the condition is met, this feed will be used to register the user.
Here is an example of a condition which will match any user who registers using a “gravitywiz.com” email address. Based on the “Role” setting for this feed, such users would be assigned the “Subscriber” user role.
Step 3: Create a User Registration Feed for Each User Role
If there are email domains that should be assigned to specific user roles, create a separate feed with the corresponding “Registration Condition” for each email domain.
Now whenever a user registers from this form, Gravity Forms will find the first matching registration feed (depending on conditional logic) and register the user (and assign their role) based on the matching feed.
How’d we do?
If you found this tutorial helpful, let us know. Also, we’d love to hear the different ways that you used this technique. Thanks!