News:

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

Main Menu

how to hide and/or display things to specific membergroups?

Started by shadav, August 08, 2020, 03:00:15 PM

Previous topic - Next topic

shadav

I know that to hide from guests
if ($user_info['is_guest'] == false)
{ CODE HERE }


but what would be for a specific user group

for example I don't want donators, moderators, and managers to see ads
or if I want to only show a specific link in the menu to said above groups....

Arantor

Doesn't ad-management have an option to show/hide from specific groups?

Failing that, you need to examine $user_info['groups'] and check with in_array, e.g. in_array(1, $user_info['groups']) if the user is in group 1.

There are many pieces of advice around here that say you should check $user_info['groups'][0] for primary group. Do NOT listen to them, this is not guaranteed to be the case. Always do in_array for 'user is in group'.

shadav

i tried that mod, i donno...didn't care much for it...i mean it's nice and all....but didn't quite suit my needs

ok i need a dummies guide  :laugh:

syntax error, unexpected 'groups' (T_STRING), expecting ',' or ';'

Shambles

Quote from: shadav on August 08, 2020, 03:23:43 PM
syntax error, unexpected 'groups' (T_STRING), expecting ',' or ';'

Err... in which file? What edits did you make?

SychO

Quote from: shadav on August 08, 2020, 03:23:43 PM
ok i need a dummies guide  :laugh:


if (in_array(group_id, $user_info['groups']))
{
    // code...
}
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

shadav

Quote from: Shambles on August 08, 2020, 03:25:21 PM
Quote from: shadav on August 08, 2020, 03:23:43 PM
syntax error, unexpected 'groups' (T_STRING), expecting ',' or ';'

Err... in which file? What edits did you make?
display.template.php
if (in_array(25, $user_info['groups']) = false)
Quote from: SychO on August 08, 2020, 03:29:59 PM
Quote from: shadav on August 08, 2020, 03:23:43 PM
ok i need a dummies guide  :laugh:


if (in_array(group_id, $user_info['groups']))
{
    // code...
}

I tried that, but still syntax error


[edit] nevermind...dumb blonde.... had my echo in the wrong place :p
it works now :) thank you

to add multiple groups would I just do
if (in_array(25,1,2,3, $user_info['groups']) == false)

Arantor

Doing multiple groups, no, that won't work.

You have two choices. For 'user is not in groups 1, 2, 3 or 25:

if (!in_array(1, $user_info['groups']) && !in_array(2, $user_info['groups']) && !in_array(3, $user_info['groups']) && !in_array(25, $user_info['groups'])) {

}


Or, the slightly more complex:
if (count(array_intersect($user_info['groups'], [1, 2, 3, 25])) == 0) {

}

shadav


Advertisement: