On: 2008/08/21 Viewed: 2972 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 :

PHP:
  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 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:

PHP:
  1. add_filter('pre_ozh_adminmenu_menu', 'myplugin_modify');
  2. add_filter('ozh_adminmenu_menu', 'myplugin_hack');
  3. add_filter('pre_ozh_adminmenu_altmenu', 'myplugin_break');
  4. 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

Metastuff

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

17 Blablas

    Pages: [2] 1 » Show All

  1. 17
    Doug United States »
    replied, 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. :-)

  2. 16
    Ozh France »
    replied, 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

  3. 15
    Doug United States »
    said, 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. :-)

  4. 14
    Doug United States »
    thought, 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

  5. 13
    Ozh France »
    replied, on 18/May/10 at 11:09 am # :

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

  6. 12
    Doug United States »
    said, 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!

  7. 11
    Doug United States »
    wrote, 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:

    CSS:
    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.

Pages: [2] 1 » Show All

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.

Close
E-mail It