On: 2008/08/21
Shorter URL for this page: http://ozh.in/lg

The wonderful Admin Drop Down Menu comes with a cool set of hooks that will allow plugin coders to hack everything to death.

Add you own plugin icon

All the plugin have, by default, a cute green plugin icon. But your plugin is special, right? It deserves its own icon!

Your plugin will need the following :

  1. // Add a page like usual
  2. add_options_page('My Plugin Settings', 'My Plugin', 10, 'myplugin', 'myplugin_do_admin_page');
  3.  
  4. // Add a cool icon
  5. add_filter( 'ozh_adminmenu_icon_myplugin', 'myplugin_icon');
  6. function myplugin_icon() {
  7.     return 'http://path/to/icon.png';
  8. }

And that's all. The trick is simply to hook into ozh_adminmenu_icon_[your_plugin].

Modify the menu itself

Third party plugins can modify the menu or its entries, with the help of the almighty add_filter() function. Note: I'm not providing any help on this, as it implies you know what you're doing, how you'll do it, and why you need to do it.

The main function of the plugin is wp_ozh_adminmenu() which builds a new $ozh_menu from WordPress' $menu and $submenu.

If your plugin needs to modify menu entries, you'll find in wp_ozh_adminmenu() various filters to do so, this means you'll write stuff like:

  1. add_filter( 'pre_ozh_adminmenu_menu', 'myplugin_modify' );
  2. add_filter( 'pre_ozh_adminmenu_submenu', 'myplugin_hack' );
  3. add_filter( 'pre_ozh_adminmenu_ozh_menu', 'myplugin_break' );
  4. add_filter( 'post_ozh_adminmenu_ozh_menu', 'myplugin_scramble' );

Read the source of wp_ozh_adminmenu(), add various debugging print_r() everywhere and you'll manage your way :)

Shorter URL

Want to share or tweet this page? Please use this short URL: http://ozh.in/lg

Metastuff

This page "API for Plugin Coders" was posted on 21/08/2008 at 7:39 pm
Watch this discussion : Comments RSS 2.0.

23 Blablas

  1. […] Update: I've update the plugin doc and added a page for plugin coders. […]

  2. Dhruva Sagar says:

    Wow man, this is simply amazing…wondering if it can get any better than this!!! :).

    Jokes apart awesome work man!

  3. […] the last update there are now not only cool icons in the drop down menu but Ozh has also provided a Plugin API for other wordpress plugin developers to be able to do very neat […]

  4. Matt says:

    Ozh,

    I love this plugin – but you've guessed what's coming next…

    I write Subscribe2 and use your API to use a custom menu icon – but it's stopped working. Now I thought it might be me or a new API change but Google Sitemaps is having the same problem on my site. You aware of any issues?

    I'm using WordPress 2.8.4 and version 3.3.2 of Admin Menu.

  5. Ozh says:

    Matt » Yeah indeed the hook has changed in a recent version of WP, totally forgot to update the doc, thanks for the reminder :) I'm updating it right now!

  6. Matt says:

    Ozh,

    Thanks for the update – got it working for my plugin :-)

    It doesn't seem to play nicely if you use __FILE__ in the admin page functions though – any tips. (At the moment I've revised who I add my menus)

  7. Daniel says:

    Matt,
    You should use something like "ozh_adminmenu_icon_my-plugin/my-plugin.php" as a hook name.

  8. Matt says:

    Daniel,

    Thanks for the tip – I renamed all my menus a while ago as a workaround and then went through some pain when many of my inbuilt links to other menus no longer worked :-) All sorted and working now though (I think!)

  9. Spencer says:

    Is there a hook to disable the menu on the fly? I have a popup page where I don't want the admin bar to appear, but I want to keep it active on the main pages.

  10. Spencer says:

    LAFFO! Nevermind. It's late and I'm on the wrong plugin page. All apologies.

  11. Doug says:

    Hey Ozh

    Awesome plugin. I'm using it on a big site for an organization that requires lots of menu items (two or three rows worth) and I am having trouble getting the CSS to make the blend background show on rows under the first row.

    I should mention I am using your plugin on WP 3.0 beta, and in regard to that I am using a child theme of Twenty Ten. So far it's CSS only, but I could add something to functions.php eventually.

    Re: the CSS troubles, I have been trying stuff like:

    1. #ozhmenu, #ozhmenu ul, #ozhmenu li {
    2.     background: #023B79 url(http://wvupci.net/wp-content/plugins/ozh-admin-drop-down-menu/inc/images/grad-trans.png) repeat-y 0px -5px;
    3. }

    Any tips? Thanks again.

  12. Doug says:

    I was not able to get the child theme's CSS page to affect the admin menu, but I edited the plugin directly and got done what I needed to do. Thanks again for a great plugin!

  13. Ozh says:

    Doug » not sure what you're trying to do. Screenshot?

  14. Doug says:

    Ozh

    Ozh

    Thanks for replying! The screenshot below shows a tweaked combination of your Admin Menu plugin PLUS the Category Write Panels plugin.

    Link to screenshot.

    At this point all I really need help on is knowing how to add a menu choice to an existing menu, preferably in a way that will survive updates, but OK if not. I have read your posts about how to do it, but I am such a newbie I am having trouble figuring it out.

    In the screenshot… The URL in the address bar is the “Edit Categories” admin page to which we have no link in the Admin menu. The “selected” dropdown menu is the Category Menu. That is where I’d like to add a menu choice labeled something like “Edit Categories” and have it point to http://wvupci.net/wp-admin/edit-tags.php?taxonomy=category

  15. Doug says:

    Hey Ozh

    Any chance I could get a tip or pointer in the right direction on how to add a link to a dropdown in the Admin Menu? I've searched for and read all I can find, but I am still a little in the dark on it. Thanks in advance for any help. :-)

  16. Ozh says:

    Doug » not currently possible but that's an easy option to add with a filter. Will implement this for the next release that will come out with WP 3.0

  17. Doug says:

    Thanks! I am trying to do it with a filter, but I searched everywhere for the source code to a function called wp_ozh_adminmenu_build() and cannot find it. Is there an API download that is separate from the plugin?

    I am an experience programmer, but all my experience is in other (older) languages. I am green and new when it comes to PHP and WP. However, I am learning quickly. If I need to create a simple plugin just to get the job done, I will do that.

    I was hoping for a little guidance on how to get started. I will not shoot the messenger if I blow something up. :-)

  18. Has the structure of the plugin changed since this was written? I can't find the function wp_ozh_adminmenu_build() anywhere in the source. I'm looking for where to add a filter that can rearrange menu items before the menu is drawn.

    Thanks for all your work, Ozh.

  19. Ozh says:

    Peter Grandstaff » Oops, indeed, don't remember when but at some point I have reworked the main function and dropped the filter. Going to push an update with those filters back.

  20. Ozh says:

    Peter Grandstaff » Indeed, things were removed in november 2008, oops. I've updated the API doc page and just committed new filters.

  21. Wow, that was fast! Thanks much! I hate plugins that add a whole new menu entry for just one page… now I can fix that without breaking on upgrade.

    I'm also tempted to try a semi-mini mode, display only 4 characters of parent items or so.

  22. brian says:

    What if my submenu is created using a URL like this:
    admin.php?page=fb_fbk

    add_submenu_page( 'option_tree', 'Flaunt', 'FB Facebook', 'manage_options', 'admin.php?page=fb_fbk', array( $this, 'fb_fbk_options_page' ) );

    I tried all of these below but none of them work.
    add_filter('ozh_adminmenu_icon_admin_page_fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));
    add_filter('ozh_adminmenu_icon_admin_page-fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));
    add_filter('ozh_adminmenu_icon_admin-page-fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));
    add_filter('ozh_adminmenu_icon_admin_page=fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));
    add_filter('ozh_adminmenu_icon_admin.php?page=fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));
    add_filter('ozh_adminmenu_icon_admin.php_page_fb_fbk', array( $fbfbk_inc,'ozh_fb_fbk'));

  23. Ozh says:

    brian » The 5th parameter of your add_submenu_page() call is wrong. It should be just 'fb_fbk'

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.