XF 2.0 Auto Assign user groups?

keithg

Member
We are looking for an easy way to add a newly registered user to a specific user group (via addon php code hooked into our existing register controller addon which provides a custom landing page redirect after registration).

I am familiar with using the admin stuff to edit a user profile and assign secondary user groups (this is what we want to do via configurable php code @ registration time). The \Xf\Entity\User object has a handy RemoveUserFromGroup but I have not been able to find any obvious corresponding method to add a user to a secondary group.

The semi-non-obvious approach would be to extend the User object and add our own AddUserToGroup method but this seems such an obvious feature that we think we are overlooking the obvious.

ideas?
 
Why not use user group promotions?
i do not fully understand what you mean - we have not looked at promotions. Can you explain more?

We are doing this at initial user registration time. The user provides some profile information during registration and based upon their choices will get assigned to a specific user group as part of registration.
 
Yea, that's what user group promotions are meant to be used for.
42979812964_054d5abda8_o.png

It might take up to an hour to actually promote the users, depending on the cron, but it might very well promote them on registration. On my quick test the user got promoted instantly.
Give it a shot.
 
Yea, that's what user group promotions are meant to be used for.
42979812964_054d5abda8_o.png

It might take up to an hour to actually promote the users, depending on the cron, but it might very well promote them on registration. On my quick test the user got promoted instantly.
Give it a shot.
Thanks - the canned behaviour does not perfectly match our needs but it did point me to the getUserGroupChangeService()->addUserGroupChange code.

Thanks!
 
Top Bottom