Admin Menu Editor For WordPress

Here is my latest and hack-iest plugin yet – Admin Menu Editor. It’s a WordPress plugin that will let you manually edit the Dashboard menu. You can reorder the menus, show/hide specific items, change access rights, and more. The plugin is still a bit rough around the edges, so a good understading of WP internals is recommended (but not required).

Features

  • Sort menu items any way you want by simple drag & drop.
  • Move a menu item to a different submenu via cut & paste. Note that if you move an item that belongs to a plugin, you will need to modify the “File” attribute to point to the right parent file (e.g. instead of “akismet-key-config” use “options-general.php?page=akismet-key-config”).
  • Edit any existing menu – change the title, access rights, menu icon and so on. Note that you can’t lower the required access rights, but you can change them to be more restrictive.
  • Hide/show any menu or menu item. A hidden menu is invisible to all users, including administrators.
  • Create custom menus that point to any part of the Dashboard. For example, you could create a new menu leading directly to the “Pending comments” page.

Here’s a screenshot :

Admin Menu Editor screenshot

Download

admin-menu-editor.zip (33 KB)

Requirements :

  • WordPress 2.7 or later
  • PHP 5 or later

Known Issues

The basic idea for the plugin was suggested by several commenters way back in October. However, the internal menu system that WordPress uses is obscure and unsuitable for direct manipulation, so I spent quite a while inventing workarounds. And even after a few weeks of pondering, there are some things I haven’t quite fixed.

  • If you delete any of the default menus they will reappear after saving. This is not a bug, it’s a feature ;)
  • As I mentioned before, the access rights required for using a particular menu item can’t be lowered, but can be made more strict. I think.
  • Also, a plugin’s menu that is moved to a different submenu will not work unless you also include the parent file in the “File” field. This is because WP “ties” the menu item to it’s parent menu and won’t recognize it in a different submenu.
  • If you create a custom menu (or change the “File” setting of an existing menu), be sure to tick the “Custom” checkbox. Otherwise that item will not show up in the final Dashboard menu.

Merry Christmas, by the way :)

Share :
  • Reddit
  • del.icio.us
  • Digg
  • StumbleUpon
  • DZone
  • Ping.fm
  • Sphinn
  • Twitter
Related posts :

271 Responses to “Admin Menu Editor For WordPress”

Pages: « 1 2 3 [4] 5 6 7 8 9 10 » Show All

  1. 62
    Mike says:

    NVM, I just realized I need to block the sub menus also.

    Now I just have to figure out how to have only EITHER the “users” or the “profile” menu visible. I dont want both to be visible to the user. The problem is the “profile” menu is not in the list of main menu items.

    Thanks for the help and a great plugin. I hope to use it to make a custom admin page eventually.

  2. 63
    Mike says:

    alright I think I have the fix to removing the users menu without interrupting the profile menu. I just removed the profile.php from the profile submenu, and created a new custom main menu and added the profile.php file to that.

    For some reason the profile.php file returned to the original profile menu and the access feild went back to read, but it does appear to be working.

    Thanks again for a great plugin, this looks like it could take the place of the roles plugin when that becomes obsolete.

  3. 64
    White Shadow says:

    I’m glad to hear you got it working.

    Regarding the “Users” and “Profile” menus, WordPress automatically adds or reconfigures them depending on the logged-in user. This is a special case that isn’t handled by the plugin, so you could end up with both menus at the same time when using it.

    I could probably fix it with some inelegant hack, but I’m lazy :)

  4. 65
    Mike says:

    Ya it is a bit hacky as your description says. You can get the users menu to disappear if you change the file and access for my profile under the users menu.

    The hacky part is that when you make another change the change you made to the my profile goes back to normal. So whenever you make a change you have to remember to go back and change the my profile.

    I am also having a similar issue with an email plugin that I want to restrict certain areas. All in all I cant complain tho. As long as it gets the job done that is all that counts.

    With this plugin I was able to hide a few menus and make my admin much less intimidating to users.

    Now I just have to figure out how to make a solid custom menu, which hopefully wont give me any trouble.

  5. 66
    Ross says:

    Hi, i get this error when trying to activate your plugin.

    Fatal error: Class ‘ReflectionClass’ not found in /home/wp/public_html/wordpress/wp-content/plugins/menu-editor/shadow_plugin_framework.php on line 101

    Im using WP 2.7.1 and I have PHP 5.2+, i have tried deactivating all my other plugins.
    Any idea what could be wrong?

  6. 67
    White Shadow says:

    The PHP documentation claims that the reflection API is included in PHP 5 by default, so either it’s been somehow turned off in your PHP configuration (I don’t know if that’s even possible), or you’re not really using PHP 5. Those arep retty much the only causes I can think of.

  7. 68
    Mike says:

    Would you be willing to write up a quick tutorial on how to use your plugin to create a top level menu page?

    I gave it a shot but couldn’t make it happen.

    thanks, MIke

  8. 69
    White Shadow says:

    What exactly is the problem? I just use the “New” button to add a custom top menu, save, add a few menu items to the new menu, and it seems to work.

  9. 70
    Mike says:

    I am looking to add a new php file to the menu. It just needs to have a link with a popout so the php file will be pretty simple. I just cant figure out what exactly needs to be in the php file.

    I have been trying to get my head around this http://codex.wordpress.org/Adding_Administration_Menus

    I have tried a few things but cant seem to get it to work.

    Maybe your plugin is not intended to work in this way…

  10. 71
    White Shadow says:

    I’m still not quite sure what you’re trying to accomplish. Do you want the menu/submenu to point to an URL outside the Dashboard? That would be impossible without writing some kind of custom redirector script or hacking the WP core, as the script that outputs menus would always mangle the external link otherwise. However, a relative URL like “/stuff/foo/bar.php” might work.

    Or maybe I’ve misunderstood your comment and what you actually want is to write a new plugin.

  11. 72
    Mike says:

    I am just trying to add a basic menu, when the user clicks on the menu item, it will bring them to the menu page that I have created. Inside that menu page will be a link, maybe that is where you were confused. I am not trying to redirect the menu to an outside page.

    I tried writing a basic plugin to handle this, but was unsuccessful. I guess I am not sure what needs to be included, the only part I do know is what will be echoed onto the page(some text with a simple popout link)

  12. 73
    White Shadow says:

    Allright, how about this super-simple plugin :

    <?php
    /*
    Plugin Name: Example Plugin
    Plugin URI: http://w-shadow.com/
    Description: Adds a menu item. That's it. 
    Version: 1.0
    Author: Janis Elsts
    Author URI: http://w-shadow.com/
    */
     
    /*
    Created by Janis Elsts (email : whiteshadow@w-shadow.com) 
    It's LGPL.
    */
     
    //Are we running in the Dashboard?
    if ( is_admin() ) {
     
        class MyMiniPlugin {
     
    		function __construct(){
    			add_action('admin_menu', array(&$this, 'hook_admin_menu'));
    		}
     
    		function hook_admin_menu(){
    			//Add a top-level menu.
    			//Note : This menu will also be automatically added as the first
    			//submenu of itself. Might be a bit confusing ;) 			
    			add_menu_page('Example Menu', 'Example Menu', 'manage_options', 
    				'example_top_menu', array(&$this, 'page_example_top_menu'));
    			//Add a submenu. Might be optional in your case. 
    			add_submenu_page('example_top_menu', 'Example Submenu', 'Example Submenu',
    				'manage_options', 'example_submenu', array(&$this, 'page_example_submenu'));
    		}
     
    		//This function outputs the HTML for "Example Menu"
    		function page_example_top_menu(){
    			echo "Top menu page";
    		}
     
    		//This function outputs the HTML for "Example Submenu"
    		function page_example_submenu(){
    			echo "Submenu page";
    		}
     
    	};
     
    	$myplugin = new MyMiniPlugin;
     
    }//is_admin()
    ?>

    It adds a top-level menu and then adds a submenu entry to that new menu. Requires PHP 5 (because I’m lazy) and should work in at least WP 2.5 and up.

  13. 74
    Bryan says:

    Best plugin ever! Thanks for your hard work.

  14. 75
    Mike says:

    Hey, thanks for doing that for me.

    Like Bryan says, this plugin is great.

    One of the biggest grey areas for wordpress modification is modifying the dashboard.

    Thanks again.

  15. 76
    Ross says:

    HI about the Reflection error, I got some sort of wierd PHP version called 5.2.6RC4-pl0-gentoo. Maybe the reflection class isnt included in that version. Im trying to get the admin to update PHP but if he wont, is there any possibility to work around this problem??

  16. 77
    White Shadow says:

    In principle, it is possible to rewrite the plugin so that it doesn’t require the reflection API, but that would take some careful editing. I’d prefer to explore other possibilities first.

  17. 78
    Mike says:

    Hey its me again, back to bother you some more.

    I finally finished up on the site that I want to link to from the admin, however when I went to change the permissions for your plugin above it gave me an error.

    The page displays for the admin but not for other users. I am wondering if it has to do with the array in there, which makes it not act like http://codex.wordpress.org/Adding_Administration_Menus.

    Hopefully its a simple change and not a trip back to the drawing board.

    THANKS.

  18. 79
    White Shadow says:

    Yes, the example plugin above is set to display the menus only for admin users (and it has nothing to do with the arrays; the arrays are how you pass an object’s method as a user-defined callback… if that makes sense).

    To allow other users to see them, you’ll need to change the capability parameter (currently set to “manage_options”) in the lines that call add_menu_page() and add_submenu_page(). See Roles and Capabilities for a list of capabilities.

    For example, if you replace ‘manage_options’ with ‘read’ then any logged-in user will see the menu.

  19. 80
    mike says:

    I should have known that. I tried using the capability instead of the role number, but for some reason I dident remove the manage_options.

    Thanks for helping with this, I hope this helps others with adding a custom menu.

  20. 81
    Ross says:

    Apparently the Reflection class wasnt included in my version of PHP. But now it is and everything is working! Great stuff!

  21. 82
    Mike says:

    I am back for more. I am trying to add the custom icon to our custom admin page, yes I am a perfectionist, and yes sometimes I wonder if I will ever understand php. I have tried so many different things to no avail. Maybe someday it will click.

    By the way nice post on the mozilla addons. I like the autopager.

  22. 83
    White Shadow says:

    Well, the documentation says you can simply add the icon URL as the last parameter when calling add_menu_page, e.g. :

    add_menu_page(
    	'Example Menu', 'Example Menu', 
    	'manage_options', 'example_top_menu', 
    	array(&$this, 'page_example_top_menu'),
    	'your-icon-URL-here'
     );

    I imagine you could use a relative URL there, like “/wp-content/plugins/myplugin/icon.png” (though hardcoding the path isn’t always a good idea).

  23. 84
    Mike says:

    I tried that approach with /images/icon.png and public_html/images/icon.png

    I then get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/aquacult/public_html/wp-content/plugins/exchangemenu.php on line 30

    this is officially my code:
    add_menu_page(‘Example Menu’, ‘Jobs Aquatic’, ‘read’,
    ‘example_top_menu’, array(&$this, ‘page_example_top_menu’)'public_html/images/icon.png’);

    You dont have to bother with this as it is not really necessary, but when I try and do something and I cant make it happen it tends to make me want to conquer and defeat the problem.

  24. 85
    White Shadow says:

    It looks like you’re missing a comma before the icon URL. And I think you don’t need the “public_html” bit.

  25. 86
    Mike says:

    Right on, that reminds me of what I read about php someplace. “Commas and semi-colons can be your worst enemy.”

    Also when I was trying this I was putting the full image url. That is the way a few of the other plugins I use work.

    Anyway thsi is what it should look like:
    add_menu_page(‘Example Menu’, ‘Jobs Aquatic’, ‘read’,
    ‘example_top_menu’, array(&$this, ‘page_example_top_menu’),’/images/icon.png’)

    Thanks for helping out with the custom wordpress admin menu.

  26. 87
    scribu says:

    Hello,

    your plugin is very useful, but if I set different access level for a top level menu, the menu is still visible to users who don’t have that capability.

  27. 88
    scribu says:

    Here is the function (simplified) which deals with capabilities:

    http://wordpress.pastebin.ca/1389987

    The problem is that it only filters submenus and leaves menus intact.

  28. 89
    scribu says:

    Sorry, this is the working version: http://wordpress.pastebin.ca/1389993

  29. 90
    White Shadow says:

    I seem to hazily remember that there was some specific reason for not filtering out top-level menus, but I don’t recall what it was. Anyway, if you also set the different access level for the submenus, WP should hide the top-level menu as it will have no visible submenus.

  30. 91
    scribu says:

    Ok, I guess that’s a solution.

    BTW, have you considered submitting this plugin to wordpress.org so that we can get automatic updates?

Pages: « 1 2 3 [4] 5 6 7 8 9 10 » Show All

Leave a Reply