Choose role when creating a new user?

Hi,

If I have for instance four custom roles and use a front-end user registration form, may I choose the role when I create the user with the function:

$users->create($data = array()) 

In the documentation, I don’t see any “role” parameter:

$user = $site->users()->create(array(
    'username'  => 'john',
    'email'     => 'john@doe.com',
    'password'  => 'secretpasswordwillbeencrypted',
    'firstName' => 'John',
    'lastName'  => 'Doe'
  ));

The code from the docs is just an example, you can add any other fields you need, including the role. :slight_smile:

Ok cool, so just like this:

$user = $site->users()->create(array(
    'username'  => 'john',
    'email'     => 'john@doe.com',
    'password'  => 'secretpasswordwillbeencrypted',
    'firstName' => 'John',
    'lastName'  => 'Doe',
    'role'      => 'my_custom_role'
  ));
1 Like

Yep, that looks about right. :slight_smile: