{"id":1001,"date":"2008-10-27T12:45:43","date_gmt":"2008-10-27T10:45:43","guid":{"rendered":"http:\/\/planetozh.com\/blog\/?p=1001"},"modified":"2008-10-25T21:15:49","modified_gmt":"2008-10-25T19:15:49","slug":"wordpress-27-featuring-your-favorite-actions","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2008\/10\/wordpress-27-featuring-your-favorite-actions\/","title":{"rendered":"WordPress 2.7 Featuring Your Favorite Actions"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/10\/wordpress-favorite-actions.gif\" alt=\"\" title=\"wordpress-favorite-actions\" width=\"307\" height=\"96\" class=\"alignleft size-full wp-image-1002\" srcset=\"https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/10\/wordpress-favorite-actions.gif 307w, https:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/10\/wordpress-favorite-actions-300x93.gif 300w\" sizes=\"auto, (max-width: 307px) 100vw, 307px\" \/>There&#39;s a very handy new function and feature in the upcoming WordPress 2.7: the <strong>favorite actions<\/strong>, showing a nice little drop down menu containing quick links to your, well, favorite tasks.<\/p>\n<p>By default, this drop down contains a link to &quot;Add New Post&quot;, &quot;Add New Page&quot; and &quot;Manage Comments&quot;. Hopefully and as usual, it&#39;s very easy to customize this menu and to add (or to remove) elements.<\/p>\n<h2>Concept<\/h2>\n<p>The new function that draws this drop down box is the well named <tt>favorite_actions()<\/tt> which calls a similarly named filter. This filter wants you to play with an array with the following structure: <tt>array( url => array ( title, level ) )<\/tt>. For instance and by default, the links are drawn by the following array:<\/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: #000088\">$actions<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #990000\">array<\/span><span style=\"color: #009900\">&#040;<\/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: #0000ff\">'post-new.php'<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #990000\">array<\/span><span style=\"color: #009900\">&#040;<\/span>__<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'Add New Post'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'edit_posts'<\/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; &nbsp; <span style=\"color: #0000ff\">'page-new.php'<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #990000\">array<\/span><span style=\"color: #009900\">&#040;<\/span>__<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'Add New Page'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'edit_pages'<\/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; &nbsp; <span style=\"color: #0000ff\">'edit-comments.php'<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #990000\">array<\/span><span style=\"color: #009900\">&#040;<\/span>__<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'Manage Comments'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'moderate_comments'<\/span><span style=\"color: #009900\">&#041;<\/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\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>The &#39;level&#39; parameter (here, &#39;edit_pages&#39; or &#39;moderate_comments&#39;) is described and explained on the Codex: <a href=\"http:\/\/codex.wordpress.org\/Roles_and_Capabilities\">Roles and Capabilities<\/a>.<\/p>\n<h2>Play with the filter<\/h2>\n<p>Now, let&#39;s modify the array, using the appropriate filter. All you need is to create a custom function that returns an array with the same structure as above.<\/p>\n<p>For instance, the following plugin would remove the link to &quot;Add new page&quot; from the favorite actions, and add a link to a fictional plugin:<\/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\"><span style=\"color: #000000;font-weight: bold\">&lt;?php<\/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: #666666;font-style: italic\">\/*<\/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: #666666;font-style: italic\">Plugin Name: Sample Favorite Actions<\/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: #666666;font-style: italic\">Plugin URI: http:\/\/planetozh.com\/blog\/<\/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: #666666;font-style: italic\">Description: Example plugin showing how to modify the favorite actions<\/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: #666666;font-style: italic\">Author: Ozh<\/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: #666666;font-style: italic\">Author URI: http:\/\/planetozh.com\/<\/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: #666666;font-style: italic\">*\/<\/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\">add_filter<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">'favorite_actions'<\/span><span style=\"color: #339933\">,<\/span> <span style=\"color: #0000ff\">'ozh_sample_fav'<\/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> ozh_sample_fav<span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000088\">$actions<\/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: #666666;font-style: italic\">\/\/ remove the &quot;Add new page&quot; link<\/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: #990000\">unset<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #000088\">$actions<\/span><span style=\"color: #339933\">&amp;<\/span><span style=\"color: #666666;font-style: italic\">#91;'page-new.php'&amp;#93;);<\/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: #666666;font-style: italic\">\/\/ add quick link to our favorite plugin<\/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: #000088\">$actions<\/span><span style=\"color: #339933\">&amp;<\/span><span style=\"color: #666666;font-style: italic\">#91;'admin.php?page=blah\/blah.php'&amp;#93; = array('Some plugin', 'manage_options');<\/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\">$actions<\/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<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\">?&gt;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>(Or, get this file: <a href=\"http:\/\/planetozh.com\/blog\/wp-content\/uploads\/2008\/10\/sample_favorite_actionsphp.txt\">sample_favorite_actions.php<\/a> and rename as .php before playing with it)<\/p>\n<h2>Pushing further : plugin idea<\/h2>\n<p>Since this menu is called &quot;favorite actions&quot;, it would be really cool to populate it with your true favorite ones. A plugin could rather easily monitor what admin pages are called and their frequency, and modify the drop down menu accordingly.<\/p>\n<p>Anyone fancy to code it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#39;s a very handy new function and feature in the upcoming WordPress 2.7: the favorite actions, showing a nice little drop down menu containing quick links to your, well, favorite tasks. By default, this drop down contains a link to &quot;Add New Post&quot;, &quot;Add New Page&quot; and &quot;Manage Comments&quot;. Hopefully and as usual, it&#39;s very [&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":[332,191,245],"class_list":["post-1001","post","type-post","status-publish","format-standard","hentry","category-published","tag-favorite_actions","tag-ideas","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1001","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=1001"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/1001\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=1001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=1001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=1001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}