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 :
-
// Add a page like usual
-
add_options_page('My Plugin Settings', 'My Plugin', 10, 'myplugin', 'myplugin_do_admin_page');
-
-
// Add a cool icon
-
add_filter( 'ozh_adminmenu_icon_myplugin', 'myplugin_icon');
-
function myplugin_icon() {
-
return 'http://path/to/icon.png';
-
}
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 functions of the plugin are:
- wp_ozh_adminmenu_build(): builds an array of all links and their anchors, class, icon, etc...
- wp_ozh_adminmenu(): uses this array to actually generate all the HTML mayhem that makes the menu itself.
If your plugin needs to modify menu entries, you'll find in wp_ozh_adminmenu_build() various filters to do so, this means you'll write stuff like:
-
add_filter('pre_ozh_adminmenu_menu', 'myplugin_modify');
-
add_filter('ozh_adminmenu_menu', 'myplugin_hack');
-
add_filter('pre_ozh_adminmenu_altmenu', 'myplugin_break');
-
add_filter('ozh_adminmenu_altmenu', 'myplugin_scramble');
Read the source of wp_ozh_adminmenu_build(), add various debugging print_r() everywhere and you'll manage your way :)
Related posts
Shorter URL
Want to share or tweet this page? Please use this short URL: http://ozh.in/lg
pingback on 21/Aug/08 at 8:58 pm # :
[...] Update: I've update the plugin doc and added a page for plugin coders. [...]
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!
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 [...]
said, 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.
thought, 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!
thought, 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)
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.
replied, 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!)
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.
commented, on 31/Jan/10 at 7:05 am # :
LAFFO! Nevermind. It's late and I'm on the wrong plugin page. All apologies.