<p><a href="https://craftcms.stackexchange.com/a/5202/45">Brandon's answer</a> is correct, as far as how Craft natively handles auto-assignment of user groups.</p>

<p>However, if you'd like to automatically assign user groups to new users <strong>when you are creating them while logged into the Control Panel</strong>, you can use this plugin built specifically for this purpose:</p>

<ul>
<li><a href="https://github.com/lindseydiloreto/craft-autoassignusergroup" rel="nofollow noreferrer">Auto-Assign User Group</a></li>
</ul>

<p>This will allow you to pre-select user groups, and those groups will be automatically assigned when you create a new user.</p>

CC BY-SA 3.0
2014-12-11T02:51:30.223Z
Hey thanks for your answer. I have updated my question.
Moin Qidwai
CC BY-SA 3.0
2014-12-11T03:19:13.450Z
That issue is because of the order in which the POST data is set... I've seen a few people get caught up by that (myself included). Solving that problem is the sole purpose of the Auto-Assign User Group plugin... feel free to download it and [check out the workaround](https://github.com/lindseydiloreto/craft-autoassignusergroup/blob/master/autoassignusergroup/AutoAssignUserGroupPlugin.php#L15)! The plugin will actually insert that data into the POST late in the process, making sure it gets saved properly.
Lindsey D
CC BY-SA 3.0
2014-12-10T19:08:40.660Z
2014-12-10T19:08:40.660Z
2017-04-13T12:51:00.200Z
Lindsey D
<p>The setting still works, but keep in mind that for it to take effect, A) you have to be registering a user through a custom registration form on the front end, and B) you have to be logged out. Without those conditions, it’s not technically <strong><em>public</em></strong> registration.</p>

<p>Default user group assignment has always taken place after the user was saved, and after the <a href="http://buildwithcraft.com/docs/plugins/events-reference#users-onSaveUser" rel="noreferrer">users.onSaveUser</a> event was called. See <a href="https://github.com/pixelandtonic/Craft-Release/blob/6d4295d3687e8ddcb3ef96772c032c72d88ac716/app/controllers/UsersController.php#L882-L894" rel="noreferrer">these highlighted lines</a> from UsersController::actionSaveUser() – the onSaveUser event gets called by <code>craft()-&gt;request-&gt;saveUser()</code>, and default group assignment happens in <code>$this-&gt;_assignDefaultGroupToUser()</code>.</p>

CC BY-SA 3.0
2014-12-11T02:52:03.433Z
Hi Brandon, thanks for your answer. Could you look at the question again as I have updated it.
Moin Qidwai
CC BY-SA 3.0
2014-12-11T14:42:41.987Z
@MoinQidwai Updated my answer.
Brandon Kelly
CC BY-SA 3.0
2014-12-12T03:29:46.060Z
Oh ok are there any plans on creating a onAfterSaveUser event later on in craft? Thanks for your time and the awesome update to craft.
Moin Qidwai
CC BY-SA 3.0
2014-12-12T15:10:29.847Z
@MoinQidwai I just added a new onAssignDefaultGroupToUser event for the next release :)
Brandon Kelly
CC BY-SA 3.0
2014-12-13T05:49:17.403Z
Seriously Awesome. Thanks for your hard work.
Moin Qidwai
CC BY-SA 3.0
2014-12-10T18:51:03.410Z
2014-12-11T14:42:33.383Z
2014-12-11T14:42:33.383Z
Brandon Kelly
<p>Hello I do not know if this is a bug or something but we just updated to craft 2.3 and got an issue which we did not have previously. 
In user settings we can set the default permissions group but when we do create a new user this group is not applied to that user.Im not sure why this is, maybe something more needs to be done beginning Craft 2.3 but the simple flow of creating a new user worked previously. Upon the user account creation the default group would be set automatically.</p>

<p>EDIT:</p>

<p>Thank you for your answers. I was mistaken it is assigning the group but I cant get that group on an event trigger.</p>

<pre><code>    craft()-&gt;on('users.saveUser', function(Event $event) {
        $user = $event-&gt;params['user'];
        var_dump($user-&gt;getGroups()); exit();
    });
</code></pre>

<p>I am doing the above in my plugins main PHP file and for some reason before updating it would give me the users group as the default one already assigned. After the update I get a empty array even though going to the control panel after registering I can see that the new user has the group assigned.</p>

<users><user-groups>
Craft 2.3 new User does not set the default permissions group
# Craft 2.3 new User does not set the default permissions group

(Asked by: username_0 on 2014-12-10)

Hello I do not know if this is a bug or something but we just updated to craft 2.3 and got an issue which we did not have previously. 
In user settings we can set the default permissions group but when we do create a new user this group is not applied to that user.Im not sure why this is, maybe something more needs to be done beginning Craft 2.3 but the simple flow of creating a new user worked previously. Upon the user account creation the default group would be set automatically.
EDIT:
Thank you for your answers. I was mistaken it is assigning the group but I cant get that group on an event trigger.
    craft()->on('users.saveUser', function(Event $event) {
        $user = $event->params['user'];
        var_dump($user->getGroups()); exit();
    });

I am doing the above in my plugins main PHP file and for some reason before updating it would give me the users group as the default one already assigned. After the update I get a empty array even though going to the control panel after registering I can see that the new user has the group assigned.

**Tags:** users, user-groups

---

## 2 answers

### Answer by username_2 on 2014-12-10. Score: 6 | Accepted answer

The setting still works, but keep in mind that for it to take effect, A) you have to be registering a user through a custom registration form on the front end, and B) you have to be logged out. Without those conditions, it’s not technically ***public*** registration.

Default user group assignment has always taken place after the user was saved, and after the [users.onSaveUser](http://buildwithcraft.com/docs/plugins/events-reference#users-onSaveUser) event was called. See [these highlighted lines](https://github.com/pixelandtonic/Craft-Release/blob/6d4295d3687e8ddcb3ef96772c032c72d88ac716/app/controllers/UsersController.php#L882-L894) from UsersController::actionSaveUser() – the onSaveUser event gets called by `craft()->request->saveUser()`, and default group assignment happens in `$this->_assignDefaultGroupToUser()`.

> **Comments:**
> **username_0**: Hi Brandon, thanks for your answer. Could you look at the question again as I have updated it.  
> **username_2**: @MoinQidwai Updated my answer.  
> **username_0**: Oh ok are there any plans on creating a onAfterSaveUser event later on in craft? Thanks for your time and the awesome update to craft.  
> **username_2**: @MoinQidwai I just added a new onAssignDefaultGroupToUser event for the next release :)  
> **username_0**: Seriously Awesome. Thanks for your hard work.  

---

### Answer by username_1 on 2014-12-10. Score: 2

[Brandon's answer](https://craftcms.stackexchange.com/a/5202/45) is correct, as far as how Craft natively handles auto-assignment of user groups.

However, if you'd like to automatically assign user groups to new users **when you are creating them while logged into the Control Panel**, you can use this plugin built specifically for this purpose:

* [Auto-Assign User Group](https://github.com/lindseydiloreto/craft-autoassignusergroup)

This will allow you to pre-select user groups, and those groups will be automatically assigned when you create a new user.

> **Comments:**
> **username_0**: Hey thanks for your answer. I have updated my question.  
> **username_1**: That issue is because of the order in which the POST data is set... I've seen a few people get caught up by that (myself included). Solving that problem is the sole purpose of the Auto-Assign User Group plugin... feel free to download it and [check out the workaround](https://github.com/lindseydiloreto/craft-autoassignusergroup/blob/master/autoassignusergroup/AutoAssignUserGroupPlugin.php#L15)! The plugin will actually insert that data into the POST late in the process, making sure it gets saved properly.  

---

