I'm working on a plugin that requires the ability to join a new PRIMARY usergroup. Naturally my first inclination was to use join_usergroup(), but that appears to add them to an additional one. Short of updating the db manually, is there a function that I could use? Or can I only do it manually?
Rebump. I'm still looking for this.
usercp.php uses both leave_usergroup() and join_usergroup() along with database queries
could not find any better method ..
require_once MYBB_ROOT."inc/datahandlers/user.php";
$userhandler = new UserDataHandler("update");
$user = array('usergroup' => $usergroup);
$userhandler->set_data($user);
if($userhandler->validate_user()) {
$userhandler->update_user();
} else {
// error handling
}
This should do the trick. Yes, it's a bit long to use but you might build a function for it and use it as you may like in your plugin.
(2013-12-01, 11:11 AM).m. Wrote: [ -> ]usercp.php uses both leave_usergroup() and join_usergroup() along with database queries
could not find any better method ..
Yeah, join_usergroup() sets a secondary group, I wanted primary.
(2013-12-01, 02:30 PM)Shade Wrote: [ -> ]require_once MYBB_ROOT."inc/datahandlers/user.php";
$userhandler = new UserDataHandler("update");
$user = array('usergroup' => $usergroup);
$userhandler->set_data($user);
if($userhandler->validate_user()) {
$userhandler->update_user();
} else {
// error handling
}
This should do the trick. Yes, it's a bit long to use but you might build a function for it and use it as you may like in your plugin.
So the only way is through a datahandler? Thanks very much.
I guess so. Unless you want to shorten it a little bit, basically this is what the datahandler does:
$db->update_query("users", array('usergroup' => $newGroup), "uid = $uid");
Remember to perform a cast to eventually incoming inputs.