-
☆ A M B ☆
- 24,524 Posts
I don't believe that you need to save the user.
I also found that using the group name rather than the ID worked for me.
$user->leaveGroup('groupname');
$user->joinGroup('groupname');
Ah, figured out why group name worked and group ID didn't - the group ID can't be a string. Drop the single-quotes; that makes MODX look for a group named "5".
-
☆ A M B ☆
- 24,524 Posts
Check the Reports->Error Log.
Here is the exact snippet I used to test with
<?php
$username = 'test';
$user = $modx->getObject('modUser', array('username'=>$username));
$user->joinGroup(3);
$user->leaveGroup(2);
$usergroup = $user->getUserGroupNames();
echo "<pre>";
print_r($usergroup);
echo "</pre>";
return;
If you are looking at the user in the Security menu, I found that I had to re-load the Manager page before my group changes showed up.