Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: fasterthanyours on October 31, 2008, 09:48:21 AM

Title: Making a menu link in the Admin.php that only admins can see in SMF 2.0
Post by: fasterthanyours on October 31, 2008, 09:48:21 AM
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.
Title: Re: Making a menu link in the Admin.php that only admins can see in SMF 2.0
Post by: Nathaniel on October 31, 2008, 09:47:36 PM
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.
Title: Re: Making a menu link in the Admin.php that only admins can see in SMF 2.0
Post by: fasterthanyours on November 01, 2008, 05:04:34 PM
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.