{"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=\"https:\/\/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 class=\"igsh-code-box\" id=\"ig-sh-1\"><pre class=\"language-php line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-php\">$actions = array(\r\n\t&#039;post-new.php&#039; =&gt; array(__(&#039;Add New Post&#039;), &#039;edit_posts&#039;),\r\n\t&#039;page-new.php&#039; =&gt; array(__(&#039;Add New Page&#039;), &#039;edit_pages&#039;),\r\n\t&#039;edit-comments.php&#039; =&gt; array(__(&#039;Manage Comments&#039;), &#039;moderate_comments&#039;)\r\n);<\/code><\/pre><\/div>\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 class=\"igsh-code-box\" id=\"ig-sh-2\"><pre class=\"language-php line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-php\">&lt;?php\r\n\/*\r\nPlugin Name: Sample Favorite Actions\r\nPlugin URI: http:\/\/planetozh.com\/blog\/\r\nDescription: Example plugin showing how to modify the favorite actions\r\nAuthor: Ozh\r\nAuthor URI: http:\/\/planetozh.com\/\r\n*\/\r\n\r\nadd_filter(&#039;favorite_actions&#039;, &#039;ozh_sample_fav&#039;);\r\n\r\nfunction ozh_sample_fav($actions) {\r\n\t\/\/ remove the &quot;Add new page&quot; link\r\n\tunset($actions[&#039;page-new.php&#039;]);\r\n\t\/\/ add quick link to our favorite plugin\r\n\t$actions[&#039;admin.php?page=blah\/blah.php&#039;] = array(&#039;Some plugin&#039;, &#039;manage_options&#039;);\r\n\treturn $actions;\r\n}\r\n\r\n?&gt;<\/code><\/pre><\/div>\n<p>(Or, get this file: <a href=\"https:\/\/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 easy to customize this menu\u2026<\/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}]}}