{"id":925,"date":"2008-08-21T02:47:12","date_gmt":"2008-08-21T00:47:12","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=925"},"modified":"2008-08-21T20:58:05","modified_gmt":"2008-08-21T18:58:05","slug":"admin-drop-down-menu-more-goodness-an-api","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2008\/08\/admin-drop-down-menu-more-goodness-an-api\/","title":{"rendered":"Admin Drop Down Menu: More Goodness &#038; an API"},"content":{"rendered":"<p><strong>Update:<\/strong> I&#39;ve update the <a href=\"http:\/\/planetozh.com\/blog\/my-projects\/wordpress-admin-menu-drop-down-css\/\">plugin doc<\/a> and added a <a href=\"http:\/\/planetozh.com\/blog\/my-projects\/wordpress-admin-menu-drop-down-css\/api-for-plugin-coders\/\">page for plugin coders<\/a>.<\/p>\n<p>I&#39;ve just committed version 2.3 of the mother of all admin menu plugins, <a href=\"http:\/\/planetozh.com\/blog\/my-projects\/wordpress-admin-menu-drop-down-css\/\">Admin Drop Down Menu<\/a>, and there are some pretty hot stuff inside. Plugin coders, be sure to read this till the end.<\/p>\n<p>First, it&#39;s finally ready for translation. That&#39;s something I&#39;ve been asked a few times, so now polyglots can rejoice since there is a .pot file included. I&#39;ve also added CSS classes and id&#39;s to all menu elements so styling maniacs can hack their stylesheet to death.<\/p>\n<p>The most visible change will be optional menu icons. That&#39;s something I&#39;ve been nagged about a gazillion times, and that I had never added because, well, <em>I<\/em> don&#39;t need them :) So, why add them now, you ask? Because I had a fun idea to implement!<\/p>\n<p>The cool stuff with this release is there is sort of an API to play with. The function that builds the array that builds the menu is full of hooks so that if your plugin needs, for some reason, to modify menu entries, you don&#39;t have to write dirty patches, just throw some <tt>add_filters()<\/tt> in (hat tip to Kevin Behrens and his plugin <a href=\"http:\/\/agapetry.net\/news\/introducing-role-scoper\/\">Role Scoper<\/a> for inspiring this)<\/p>\n<p>But wait, there&#39;s more, and cooler!<\/p>\n<p>Icons are stolen from the awesome <a href=\"http:\/\/www.famfamfam.com\/\">FamFamFam<\/a>, of course. By default, plugins get a cute green plugin icon, but this can get a bit boring when you have dozens of plugin entries looking the same. Plugin coders want their individuality!<\/p>\n<p>Well, they can have it: <strong>there&#39;s an awesomely super cool hook that allows plugins to have their own icon!<\/strong> (I&#39;m pretty excited with this feature:)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"370\" height=\"207\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/08\/adminmenu-hook.png\" alt=\"\" title=\"adminmenu-hook\" class=\"aligncenter size-full wp-image-926\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/08\/adminmenu-hook.png 370w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/08\/adminmenu-hook-300x167.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>To do so, simply add the following in your plugin:<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">php<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"php\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">add_filter<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'ozh_adminmenu_icon'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_icon'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">function<\/span> myplugin_icon<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000088\">$hook<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #b1b100\">if<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000088\">$hook<\/span> <span style=\"color: #339933\">==<\/span> <span style=\"color: #0000ff\">'myplugin'<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #0000ff\">'http:\/\/url\/to\/cute\/icon.png'<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #000088\">$hook<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Where <tt>'myplugin'<\/tt> is the <tt>$file<\/tt> argument used to add your administration page (for instance <tt>add_options_page('My Plugin', 'My Plugin', 10, '<b>myplugin<\/b>', 'myplugin_do_stuff')<\/tt>)<\/p>\n<p>If you use this cool feature in your plugin (or need help to do so) be sure to let me know!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: I&#39;ve update the plugin doc and added a page for plugin coders. I&#39;ve just committed version 2.3 of the mother of all admin menu plugins, Admin Drop Down Menu, and there are some pretty hot stuff inside. Plugin coders, be sure to read this till the end. First, it&#39;s finally ready for translation. That&#39;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[284,85,245],"class_list":["post-925","post","type-post","status-publish","format-standard","hentry","category-published","tag-admin-drop-down-menu","tag-plugins","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=925"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/925\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}