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

menu-editor.zip (27 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 ;)
  • You can’t use arbitrary URLs as menu targets because WordPress will automatically strip off the “http:/”.
  • 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.

Merry Christmas, by the way :)

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

139 Responses to “Admin Menu Editor For WordPress”

Pages: « 1 2 3 [4] 5 » Show All

  1. 80
    Bryan says:

    Best plugin ever! Thanks for your hard work.

  2. 81
    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.

  3. 82
    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??

  4. 83
    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.

  5. 84
    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.

  6. 85
    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.

  7. 86
    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.

  8. 87
    Ross says:

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

  9. 88
    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.

  10. 89
    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).

  11. 90
    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.

  12. 91
    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.

  13. 92
    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.

  14. 93
    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.

  15. 94
    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.

  16. 95
    scribu says:

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

  17. 96
    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.

  18. 97
    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?

  19. 98
    White Shadow says:

    Yes, but I’m very lazy in this respect :P

  20. 99
    Bryan says:

    Anyway to make this work with PHP4?

  21. 100
    White Shadow says:

    One could try, but it would take a lot of rewriting.

    You’d need to set all hooks manually – the “magic” self-installing hooks of my makeshift plugin framework depend on the Reflection API, which is PHP5-specific. Class constructions would need to be renamed. Some variable initializers might not work in PHP 4 (arrays?). There’s probably a foreach() loop or two that use the iterator by reference (also not supported in PHP4). And so on.

  22. 101
    sbdesign says:

    Thanks for this great plugin! I looked for ages to find something to simplify the administration menus for my clients. Good work!

  23. 102
    phpworker says:

    Well, it does just what I need – great plug! Thanks a lot :)

  24. 103
    Robert Neuschul says:

    First, thanks for what is a really useful plugin.

    Second, the problem [you just knew there had to /be/ a problem :-) ]: not sure if this comes about from trying to do too much with ME, or as a result of an interaction with other plugins. It _only_ happens on one site where there are some 20 or so plugins installed [it's a very complex "private" members-only site]

    Problem Description: open menu editor from Settings menu, go to “settings” sub-menu, sort all plugins [not default WP items] into alphabetical order below the default WP elements. Save. Refresh page. Go to Settings menu: Menu Editor itself has vanished from the Settings menu and one or more other plugins may also have vanished, whilst one or more plugins may be duplicated in the Settings at odd non-alphabetical places in that settings menu. Duplicate items _are_ functional.

    Go back to Menu Editor via the installed plugins page or via direct URL and ME shows everything correctly as last saved: not as shown on the settings menu.

    Clearing the WP Cache makes no difference. Clearing the browser cache makes no difference. Indeed the problem is visible from different machines on different OSs and using several different browsers etc etc.

    Reset menus to default order, save and refresh and everything instantly works as expected.

    Have tried deactivating Menu Editor, cleaning out the options table and then reactivating, but the problem reappears fairly quickly once one starts sorting entries.
    I’ve not yet had the courage to deactivate all other plugins and/or reset the WP options table to defaults in order to do a ‘clean’ test because this is such a complex site.

    NB: this problem does _not_ arise on other less complex sites running on the same configuration of Apache/Linux with PHP5.n and MySQL5.n and WP 2.7.1 [they're all virtual hosts on the same physical box], although many of them do share several of the same plugins.

    Having to run with default order in the Settings menu isn’t a major issue, but missing and/or duplicate items could become a problem. Most of all it’s an irritant which is puzzling me.

    Any thoughts or suggestions?

  25. 104
    White Shadow says:

    Yep, this might really be a compatibility issue. So muster up the courage and test that idea :) – First, save the sorted configuration. Then deactivate/reactivate your other plugins one by one. Reload the page aftear each deactivated plugin and see if the menu is OK. That should help you find the conflicting one.

    Personally, I’m pretty sure it is a plugin conflict. Sorting works fine even in WP 2.8 beta, though there are some glitches with separators.

  26. 105
    Gianfranco says:

    Hi, with the purpose to check plugin compatibility behaviour with 2.0, I duplicated my WordPress site and upgraded. Strangely all my settings in the Menu Editor were resetted to default.
    Tha means I should go and re-arrange everything again after upgraded to 2.8. Is this normal? Anybody else met the same issue? If yes, are there any fixes to this?

    By the way, this is the bes plugin ever! Letting you customize your admin is someting that should be considered as a default option in any CMS. Luckly, White Shadow did a great work with this. Thanks.

  27. 106
    White Shadow says:

    For what it’s worth, upgrading to WP 2.8 worked fine for me – the settings were retained and the plugin still worked as expected. Perhaps in your case the settings were actually lost in the duplication process?

  28. 107
    Gianfranco says:

    I got a question.

    I finished the development for a site (on local) and now I need to put it on the live server. Even without upgrading to 2.8, whenever I copy all my files to the server and I import the databse, the Menu Editor plugin doesn’t keep its settings I set up on local.

    Well, actually, I even made a test from local to local (copy files + export/import databse) and I got the same result.

    I got the default admin menus and I need to re-arrange them all with Menu Editor again. Is there a reason why that happens. Is it a normal behaviour or a bug?

    You say, “perhaps in your case the settings were actually lost in the duplication process?”. How is that possible? Where and what should I look to see where the problem might be?

    Thanks for letting me know.

  29. 108
    White Shadow says:

    All settings pertaining to this plugin are stored in the “ws_menu_editor” option. Options are, in turn, saved in the wp_options table in the WordPress DB. You can view the database with something like phpMyAdmin (or whatever other tool your host has).

    You could check the “ws_menu_editor” option before and after copying, and try to figure out when/why it changes or gets deleted.

  30. 109
    Robert Neuschul says:

    One can view the stored options without the use of phpMyAdmin or the MySQL Administrator Toolkit.

    http://my_site_url/wp-admin/options.php

    It’s not guaranteed to be true but it’s my observation that where other plugins are using the now deprecated get_settings call in their coding, instead of the get_options call, such plugins will interfere with the correct deployment of menu editor.

    I’ve seen exactly the behaviour you describe. The only way I’ve found to force menu editor to behave correctly thereafter is to export all WP content, de-activate all plugins, drop and then recreate the DB tables and then reimport the WP content and re-activate ONLY the menu editor plugin and set it as one wishes it to behave. Once that’s been done one can reactivate the other plugins one at a time until one finds which plugin or combination of plugins causes the menu editor to stop functioning. At that point it’s a case of hacking through the code of the problem plugin and replacing any get_settings calls.

Pages: « 1 2 3 [4] 5 » Show All

Leave a Reply