2020-06-12, 06:51 AM
Hello there,
I think that a small function is missing in MyBB, I called it "is_membergroup". This is really similar to native
why ? I made a plugin in which I list users and I just want the members of authorized groups. Each use of is_member() makes a query
I think that a small function is missing in MyBB, I called it "is_membergroup". This is really similar to native
is_member()
but don't query for user, the user groups are arguments of the function.why ? I made a plugin in which I list users and I just want the members of authorized groups. Each use of is_member() makes a query
select * from mybb_users where uid=<id>
. But as I already get the interresting datas about all users (including their groups), I think it's better to just compare what I have with what I want, without other queries./**
* Checks if usergoup ou additionalgroups are in groups
* @param array|int|string $groups A selection of groups (as array or comma separated) to check or -1 for any group
* @param int $usergroup the main group of an user
* @param string $additionalgroups A comma separated list of additional groups
* @return array Matching groups
*/
function is_membergroup($groups, $usergroup=0, $additionalgroups='') {
$memberships = array_map('intval', explode(',', $additionalgroups));
$memberships[] = $usergroup;
if(!is_array($groups)) {
if((int)$groups == -1) {
return $memberships;
} else {
if(is_string($groups)) {
$groups = explode(',', $groups);
} else {
$groups = (array)$groups;
}
}
}
$groups = array_filter(array_map('intval', $groups));
return array_intersect($groups, $memberships);
}