How to assign a role automatically when creating a user?

We may need to assign a role automatically to users who register on a Drupal site. This avoids having to do it in the admin if the account needs to be validated and it allows users to have the right role if the account is activated automatically.

Assign a role automatically when creating a user

We can do it with hook but there is a module that does it very simply: Registration role

This module allows to assign a role when the user registers on a site via the form /user/register

The module offers an option that allows not to assign the role if the user is created from the back office. This is practical because it allows you to create admins, for example, who will not have the role of users who register in front.

Screenshot of the "registration role" module
registration role module Drupal

Other useful resources

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.