Title: Automatically define user roles
Last modified: August 20, 2016

---

# Automatically define user roles

 *  [4elhagen](https://wordpress.org/support/users/4elhagen/)
 * (@4elhagen)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/automatically-define-user-roles/)
 * I have been working on a website that will have employee and customer users. 
   All users will be able to register themselves, but I would like the user groups
   to be defined automatically by the email domain.
 * For example, the employee uses the address [employee@companyname.com](https://wordpress.org/support/topic/automatically-define-user-roles/employee@companyname.com?output_format=md),
   is there any way to get the @companyname.com users to be automatically defined
   as employees instead of having them lumped in with the customers/subscriber role
   so they don’t have to be manually changed?

Viewing 1 replies (of 1 total)

 *  [Damian Gostomski](https://wordpress.org/support/users/gostomski/)
 * (@gostomski)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/automatically-define-user-roles/#post-2209083)
 * You can hook in on the “user_register” action, which receives the user ID as 
   a parameter.
 * From this, you can get the users email address, and then to change the role they’re
   on, just do the following:
 *     ```
       $user = new WP_User($user_id);
       $user->remove_role('subscriber');
       $user->add_role('employee');
       ```
   
 * Hope this helps

Viewing 1 replies (of 1 total)

The topic ‘Automatically define user roles’ is closed to new replies.

## Tags

 * [role](https://wordpress.org/support/topic-tag/role/)
 * [users](https://wordpress.org/support/topic-tag/users/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Damian Gostomski](https://wordpress.org/support/users/gostomski/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/automatically-define-user-roles/#post-2209083)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
