News:

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

Main Menu

Making a menu link in the Admin.php that only admins can see in SMF 2.0

Started by fasterthanyours, October 31, 2008, 09:48:21 AM

Previous topic - Next topic

fasterthanyours

I'd like to make an item on one of the drop down menus like "reports" only visible to Admins, not moderators.

So I searched for this and I can't really find anything, well anything that makes sense to me.
I saw these two threads, but they really didn't directly address my question.
http://www.simplemachines.org/community/index.php?topic=248712.0
http://www.simplemachines.org/community/index.php?topic=233429.0

I'm modding the admin.php with the following.
'MenuItem' => array(
'label' => $txt['MenuItem'],
'file' => 'MenuItem.php',
'function' => 'MenuItem',
'icon' => 'MenuItem.gif',
),


I found this code if ($context['user']['is_admin']) but it didn't work when I put it in the admin.php

Am I doing this all wrong or should the is_admin call be in the MenuItem.php?  But that doesn't make sense, because then the MenuItem will show up in the Admin section, but it wouldn't do anything when you clicked on it.

Nathaniel

To make it admin only, you will have to change your code slightly:
               'MenuItem' => array(
                  'label' => $txt['MenuItem'],
                  'file' => 'MenuItem.php',
                  'function' => 'MenuItem',
                  'icon' => 'MenuItem.gif',
                  'permission' => array('admin_forum'),
            ),


You should also have the 'is_admin' check in your MenuItem.php file as well. The code above will now check if they are an admin when putting in the link. The code in your 'MenuItem.php' file will make sure that they can't use the functions/page that you have added, unless they are admin.
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

fasterthanyours

I was concern about the Moderators being able to see that menu item, but I just tested my fake Mod and they can't even get to the area of the menu I'm installing it.

Thanks anyway.

Advertisement: