I added following code in onUserBeforeSave of user profile plugin(plugins/user/profile/profile.php):
if ($isnew)
{
if (!strcasecmp($data['role'], 'group0'))
{
$data['groups'] = array(10);
}
elseif (!strcasecmp($data['role'], 'group1'))
{
$data['groups'] = array(11);
}
JFactory::getApplication()->enqueueMessage(print_r($user, true));
JFactory::getApplication()->enqueueMessage(print_r($data, true));
}
The print_r results show the $data has been modified successfully, but in the end, the new user added to database still in old group, which is 'Registered'.
I am not sure what's the reason for this. And how can I achieve overriding default user groups. Thanks!