Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

How can I know if current user is Global Moderator in SMF 1.1.x & 2.0.x?

Aloittaja davidhs, joulukuu 23, 2013, 08:46:30 AP

« edellinen - seuraava »

davidhs

I detect if current user is Local Moderator with this code
if ($context['user']['is_mod'])
$user = 'localmod';


but how can I detect if is a Global Moderator?

In 2.0.x exists variable $context['user']['can_mod'] but it is always 1 for local/global moderator.

Arantor

You can use in_array(2, $user_info['groups']) for the original Global Moderator group but you can't necessarily rely on that as users frequently make their own global moderator groups. Going by permissions is much more reliable; usually allowedTo('moderate_forum') is the one you will want.
Holder of controversial views, all of which my own.


davidhs

Thanks.

I will use allowedTo('moderate_forum') (exists in SMF 1.1.x & 2.0.x)

I would have liked something like $context['user']['is_global_mod'] :(

Arantor

Except such a concept does not and cannot meaningfully exist except by doing the thing I just suggested.

This forum, for example, does not have group 2 any more so you can't use that for testing purposes. So the only thing you can actually use is whether they have the global permission for it which is what you're doing.

And even if, for some strange reason, $context['user']['is_global_mod'] existed, all it would be would be the result of allowedTo('moderate_forum') anyway...
Holder of controversial views, all of which my own.


davidhs

Lainaus käyttäjältä: Arantor Beeblebrox the First - joulukuu 23, 2013, 12:45:26 IP
And even if, for some strange reason, $context['user']['is_global_mod'] existed, all it would be would be the result of allowedTo('moderate_forum') anyway...
Already exist
$context['user']['is_admin'] = $user_info['is_admin'] = in_array(1, $user_info['groups'])
$context['user']['is_guest'] = $user_info['is_guest'] == $id_member == 0,
$context['user']['is_logged'] = !$user_info['is_guest']
$context['user']['is_mod'] = $user_info['is_mod'] = ...

there could be
$context['user']['is_global_mod'] = $user_info['is_global_mod'] = allowedTo('moderate_forum')
It would be more "readable".

Perhaps in SMF 2.1 :D

Arantor

I'd rather remove $context['user'] (and just have $user_info) than add more to it. But I say again: is_global_mod does not make sense and I will not add it. I will also not merge this in as a PR because it simply isn't worth it. Because it's ambiguous - what you call 'is global moderator' is not what others will call it.

Some people will interpret it as 'people in the Global Moderator group', i.e. group 2 which is a regular group that can be removed and replaced with other global moderator groups which wouldn't be detected.
Holder of controversial views, all of which my own.


Advertisement: