Menu Permissions?

Started by Ghost1227, March 13, 2012, 04:42:38 AM

Previous topic - Next topic

Ghost1227

I've been working on editing my site menu by tweaking the Subs.php file, and I've added a menu item to the array as follows:

'my_page' => array(
    'title' => $txt['my_page'],
    'href' => $scripturl . '?page=my_page',
    'show' => true,
),


The menu item itself works fine, but I want it to only be visible to members of certain member groups. Any suggestions as to how I might accomplish this?

kat

Hi and welcome to the forum!

Looking at the default theme's index.tempate.php (In SMF v1.1.16), it looks like something along the lines of:

if ($context['allow_calendar'])

is used.

I'm no coder, unfortunately. But, maybe something like that would do the job?

Seems that v2, with Subs.php, they use something similar.

$context['allow_calendar'] = allowedTo('calendar_view') && !empty($modSettings['cal_enabled']);

All Colours Sam

Hi, welcome to SMF.

You would have o do a check on this user groups with $user_info, a ternary check:

'show' => in_array($user_info['groups'][0], array(1)) || in_array($user_info['groups'][1], array(1)) ? true : false,


Where  array(1)  is the membergroup ID you want to have access,  could be several groups:  array(1,2,3,4,5).

This also depends if you only want to include post based groups or regular groups.
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Ghost1227

That's exactly what I needed! Thanks so much!

Advertisement: