JUserHelper/removeUserFromGroup: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to remove a user from a group.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JUserHelper/removeUserFromGroup|Edit Descript... |
m preparing for archive only |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
Method to remove a user from a group. | Method to remove a user from a group. | ||
===Syntax=== | ===Syntax=== | ||
| Line 67: | Line 65: | ||
</source> | </source> | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=removeUserFromGroup | category=removeUserFromGroup | ||
category=JUserHelper | category=JUserHelper | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 02:16, 25 March 2017
Description
Method to remove a user from a group.
Syntax
static removeUserFromGroup($userId, $groupId)
| Parameter Name | Default Value | Description |
|---|---|---|
| $userId | $userId The id of the user. | |
| $groupId | $groupId The id of the group. |
Returns
mixed Boolean true on success, on error.
Defined in
libraries/joomla/user/helper.php
Importing
jimport( 'joomla.user.helper' );
Source Body
public static function removeUserFromGroup($userId, $groupId)
{
// Get the user object.
$user = & JUser::getInstance((int) $userId);
// Remove the user from the group if necessary.
if (array_key_exists($groupId, $user->groups))
{
// Remove the user from the group.
unset($user->groups[$groupId]);
// Store the user object.
if (!$user->save()) {
return new JException($user->getError());
}
}
// Set the group data for any preloaded user objects.
$temp = & JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = & JFactory::getUser();
if ($temp->id == $userId) {
$temp->groups = $user->groups;
}
return true;
}
Examples
Code Examples