On: 2008/08/21 Viewed: 6067 times
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. 1
    Admin Drop Down Menu: More Goodness &... United States »
    pingback on 21/Aug/08 at 8:58 pm # :

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

  2. 2
    Dhruva Sagar India »
    thought, on 22/Aug/08 at 4:22 pm # :

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

    Jokes apart awesome work man!

  3. 3
    Admin Drop Down Menu | A Wor[l]d of Ment... United States »
    pingback on 22/Aug/08 at 4:42 pm # :

    [...] 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. 4
    Matt United Kingdom »
    thought, on 08/Sep/09 at 9:10 pm # :

    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. 5
    Ozh France »
    wrote, on 08/Sep/09 at 9:28 pm # :

    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. 6
    Matt United Kingdom »
    said, on 09/Sep/09 at 11:11 am # :

    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. 7
    Daniel Poland »
    commented, on 11/Oct/09 at 10:04 pm # :

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

  8. 8
    Matt United Kingdom »
    wrote, on 12/Oct/09 at 9:11 am # :

    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. 9
    Spencer United States »
    replied, on 31/Jan/10 at 6:59 am # :

    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. 10
    Spencer United States »
    thought, on 31/Jan/10 at 7:05 am # :

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

  11. 11
    Doug United States »
    commented, on 17/May/10 at 12:39 am # :

    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. 12
    Doug United States »
    thought, on 17/May/10 at 6:52 am # :

    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. 13
    Ozh France »
    replied, on 18/May/10 at 11:09 am # :

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

  14. 14
    Doug United States »
    replied, on 18/May/10 at 7:45 pm # :

    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. 15
    Doug United States »
    thought, on 20/May/10 at 6:52 am # :

    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. 16
    Ozh France »
    said, on 20/May/10 at 9:17 pm # :

    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. 17
    Doug United States »
    thought, on 21/May/10 at 12:09 am # :

    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. 18
    Peter Grandstaff United States »
    thought, on 21/Oct/10 at 4:59 pm # :

    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. 19
    Ozh France »
    commented, on 21/Oct/10 at 9:11 pm # :

    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. 20
    Ozh France »
    wrote, on 21/Oct/10 at 9:25 pm # :

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

  21. 21
    Peter Grandstaff United States »
    said, on 21/Oct/10 at 9:37 pm # :

    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. 22
    brian United States »
    wrote, on 02/Jun/11 at 4:24 pm # :

    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. 23
    Ozh France »
    commented, on 02/Jun/11 at 7:53 pm # :

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

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.