News:

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

Main Menu

Is it possible to have a button visible by membergroup.

Started by Snogmarr, May 10, 2010, 10:48:27 AM

Previous topic - Next topic

Snogmarr

I know I can put a button in my header and action it, but I was wondering if it was possible to have a button only viewable by a particular member group.
I know I can either have guest or member access for viewing of a button but I require a specific member group not generic?

Please advise

Thanks!

Arantor

* Arantor wonders what version of SMF, like the big READ FIRST topic says.

Arantor

No, the reason I asked is because it's totally different between 1.1.x and 2.0 RCx.

In 1.1.x you make tabs visible based on code in index.template.php, which I'd need to see the actual code for because it's modifying an if() statement. In 2.0 RCx it's an edit to Subs.php, based on modifying an array with a specific 'show' parameter.

And since you pointed those threads out, you should probably try reading them a little closer, since in each case the version wasn't relevant.


So, what link, what membergroups should it be visible to?

Snogmarr

So the answer is yes it can be done?

Would it be possible to expand this into how?

Arantor

Sure it can be done. I do this in SimpleDesk all the time (in fact, I know right now for example there is a Helpdesk button available to both you and me because we're both Charter Members, that is not available to non Charter members)

But you need to answer my two questions first. What button and what group? Is it based instead on a permission?


In reality the question to ask isn't "can it be done?" since almost anything can. The questions to ask are "is it *practical*" and "is it worth it". In most cases this is worth it.

Snogmarr

I have a member group on one of my business forums which I have called trade.
I wish to create a button called trade that only appears to trade members, from this I wish to direct them to a trade price list on my website.
The problem I have been having is making the button appear to the trade member group only.

As a footnote I was categorically told by the help desk that any question posted must refer to issues with the workings of rc3 only and nothing else, or believe me I would have posted question upon question by now.


Arantor

Referring to your footnote, that's correct. I was simply pointing out that the helpdesk button isn't visible to people outside the Charter group.


So have you already made the button on your forum? Which membergroup id is this trade group? (You can find this from the membergroup editing screen, it'll have the id in the URL, IIRC it says ;group=x where x is the id)

Snogmarr

sorry the guest button on the drop down I have sent to the web page but I can only get then to appear or disappear on guest or member access

Arantor

How did you add that code? I thought we were talking about something on the main menu - that's something quite different...

Arantor

Well, to set group access, 'show' => in_array(id, $user_info['groups']),

But that requires you know what number to put in id. For example Global Moderators are group 2. In which case, something visible only to global moderators would be: 'show' => in_array(2, $user_info['groups']),

As for your link not doing anything, $scripturl. '?action=www.ukeye.org' means to make http://www.ukeye.org/index.php?action=www.ukeye.org which unless you've modified index.php, isn't going to do anything.

The links have to be working before you add them to the menu; just adding things to the main menu doesn't make them somehow magically work.

Arantor

If 11 is the Trade usergroup, 'show' => in_array(11, $user_info['groups']), will cause it to only show the item to users who have group 11 as at least one of their groups.

Snogmarr

Yeah that's all I want!

It to show under user group 11
the rest I can work out with trial and error thanks.

Arantor

There's two ways, depends really on whether it's two or multiple groups.

'menu3' => array(
            'title' => 'Trade',
          'href' => "http://www.ukeye.org",
           'show' => in_array(7,$user_info['groups']) || in_array(6,$user_info['groups']),
         ),     


'menu3' => array(
            'title' => 'Trade',
          'href' => "http://www.ukeye.org",
           'show' => !empty(array_intersect(array(6,7), $user_info['groups'])),
         ),     


The first one performs generally better when it's just two groups under consideration, the second when it's possibly lots more.

Snogmarr


~DS~

Interesting Arantor, so that's how it's done for dropdown menu like project subs in SD and simliar to the code you did for me.
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Arantor

Sort of, yeah.

It's slightly different on SD.net but the basis is the same.

In the case of SD.net we have a file called Subs-Site.php, which contains a bunch of site stuff, amongst which is a function called doResourcesCheck. In the same way you have $user_info['is_admin'] and $user_info['is_guest'], we also have $user_info['is_team'], $user_info['is_betatester'] and more stuff like that, so IIRC the menu checks for $user_info['is_betatester'] || $user_info['is_team'] for some items. Can't remember the exact changes though.

Advertisement: