• 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 [email protected], 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)
  • 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.