{"id":931,"date":"2008-08-21T19:39:48","date_gmt":"2008-08-21T17:39:48","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?page_id=931"},"modified":"2010-10-21T21:26:21","modified_gmt":"2010-10-21T19:26:21","slug":"api-for-plugin-coders","status":"publish","type":"page","link":"https:\/\/planetozh.com\/blog\/my-projects\/wordpress-admin-menu-drop-down-css\/api-for-plugin-coders\/","title":{"rendered":"API for Plugin Coders"},"content":{"rendered":"<p>The wonderful <a href=\"http:\/\/planetozh.com\/blog\/my-projects\/wordpress-admin-menu-drop-down-css\/\">Admin Drop Down Menu<\/a> comes with a cool set of hooks that will allow plugin coders to hack everything to death.<\/p>\n<h2>Add you own plugin icon<\/h2>\n<p>All the plugin have, by default, a cute green plugin icon. But <b>your<\/b> plugin is special, right? It deserves its own icon!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"370\" height=\"207\" class=\"aligncenter size-full wp-image-926\" title=\"adminmenu-hook\" alt=\"\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/08\/adminmenu-hook.png\" 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>Your plugin will need the following :<\/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\"><span style=\"color: #666666;font-style: italic\">\/\/ Add a page like usual<\/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\">add_options_page<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'My Plugin Settings'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'My Plugin'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #cc66cc\">10<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_do_admin_page'<\/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: #666666;font-style: italic\">\/\/ Add a cool icon<\/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\">add_filter<span style=\"color: #009900\">&#040;<\/span> <span style=\"color: #0000ff\">'ozh_adminmenu_icon_myplugin'<\/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\"><span style=\"color: #000000;font-weight: bold\">function<\/span> myplugin_icon<span style=\"color: #009900\">&#040;<\/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\">return<\/span> <span style=\"color: #0000ff\">'http:\/\/path\/to\/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\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>And that&#39;s all. The trick is simply to hook into <tt>ozh_adminmenu_icon_[your_plugin]<\/tt>.<\/p>\n<h2>Modify the menu itself<\/h2>\n<p>Third party plugins can modify the menu or its entries, with the help of the almighty add_filter() function. Note: I&#39;m not providing any help on this, as it implies you know what you&#39;re doing, how you&#39;ll do it, and why you need to do it.<\/p>\n<p>The main function of the plugin is <tt>wp_ozh_adminmenu()<\/tt> which builds a new <tt>$ozh_menu<\/tt> from WordPress&#39; <tt>$menu<\/tt> and <tt>$submenu<\/tt>.<\/p>\n<p>If your plugin needs to modify menu entries, you&#39;ll find in <tt>wp_ozh_adminmenu()<\/tt> various filters to do so, this means you&#39;ll write stuff like:<\/p>\n<div id=\"ig-sh-2\" 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\">'pre_ozh_adminmenu_menu'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_modify'<\/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\">add_filter<span style=\"color: #009900\">&#040;<\/span> <span style=\"color: #0000ff\">'pre_ozh_adminmenu_submenu'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_hack'<\/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\">add_filter<span style=\"color: #009900\">&#040;<\/span> <span style=\"color: #0000ff\">'pre_ozh_adminmenu_ozh_menu'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_break'<\/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\">add_filter<span style=\"color: #009900\">&#040;<\/span> <span style=\"color: #0000ff\">'post_ozh_adminmenu_ozh_menu'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'myplugin_scramble'<\/span> <span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Read the source of <tt>wp_ozh_adminmenu()<\/tt>, add various debugging <tt>print_r()<\/tt> everywhere and you&#39;ll manage your way :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":450,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-931","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/pages\/931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"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=931"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/pages\/931\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/pages\/450"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}