In: , ,
On: 2008 / 10 / 27
Shorter URL for this post:

There'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 "Add New Post", "Add New Page" and "Manage Comments". Hopefully and as usual, it's very easy to customize this menu and to add (or to remove) elements.


The new function that draws this drop down box is the well named favorite_actions() which calls a similarly named filter. This filter wants you to play with an array with the following structure: array( url => array ( title, level ) ). For instance and by default, the links are drawn by the following array:

  1. $actions = array(
  2.     'post-new.php' => array(__('Add New Post'), 'edit_posts'),
  3.     'page-new.php' => array(__('Add New Page'), 'edit_pages'),
  4.     'edit-comments.php' => array(__('Manage Comments'), 'moderate_comments')
  5. );

The 'level' parameter (here, 'edit_pages' or 'moderate_comments') is described and explained on the Codex: Roles and Capabilities.

Play with the filter

Now, let'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.

For instance, the following plugin would remove the link to "Add new page" from the favorite actions, and add a link to a fictional plugin:

  1. <?php
  2. /*
  3. Plugin Name: Sample Favorite Actions
  4. Plugin URI:
  5. Description: Example plugin showing how to modify the favorite actions
  6. Author: Ozh
  7. Author URI:
  8. */
  10. add_filter('favorite_actions', 'ozh_sample_fav');
  12. function ozh_sample_fav($actions) {
  13.     // remove the "Add new page" link
  14.     unset($actions&#91;'page-new.php']);
  15.     // add quick link to our favorite plugin
  16.     $actions&#91;'admin.php?page=blah/blah.php'] = array('Some plugin', 'manage_options');
  17.     return $actions;
  18. }
  20. ?>

(Or, get this file: sample_favorite_actions.php and rename as .php before playing with it)

Pushing further : plugin idea

Since this menu is called "favorite actions", 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.

Anyone fancy to code it?

Shorter URL

Want to share or tweet this post? Please use this short URL:


This entry "WordPress 2.7 Featuring Your Favorite Actions" was posted on 27/10/2008 at 12:45 pm and is tagged with , ,
Watch this discussion : Comments RSS 2.0.

12 Blablas

  1. James Dimick says:

    Great article! I'm glad someone took the time to write about this new functionality. I was actually looking for a reference for this new functionality (for a new plugin I'm working on for WordPress 2.7) but couldn't find anything so I just ended up using this:

    1. function myplugin_add_favorite_actions($actions) {
    2.     $newactions = array('?page=my-plugin-page' =&gt; array(__('My Plugin Page'), 'manage_options'), '?page=my-other-plugin-page' =&gt; array(__('My Other Plugin Page'), 'manage_options'));
    3.     $result = array_merge($actions, $newactions);
    4.     return($result);
    5. }

    But, now that I see how you're supposed to do it I can fix the way I'm doing it. Thanks for the post! Really helpful!

  2. Ozh says:

    James » My pleasure ! :)

  3. […] Ozh has written up a nice article on the new WordPress 2.7 Favorite Actions menu and puts out the call to developers to write a plugin that would automagically determine the favorite actions of a particular blogger and populate that menu with those options. That would be a truly useful plugin and I would love to see it. Now that we are talking about the Favorite Actions menu and we know that actions can be removed, is there going to be competition/confusion between plugin authors who want to add a link to their plugin's admin page to the top of that menu? Anyone plan on writing such a plugin? […]

  4. modbo says:

    Thank you for the useful WordPress hints. You've made very good enquiries.

  5. Fujilives says:

    Personally I see this "quick menu" or "favorite actions" a waste of space. It provides no real "new" functionality!

    With Ozh admin dropdown menu I could navigate my entire site like in the same way I can via single, manual, additions with the "favorite actions" dropdown. To me it seems like wasted space that saves no time – it also shows potential flaws with the new side-menu. Why would we need a new menu up top if the side-menu is fast enough to navigate?

  6. […] WordPress 2.7 Featuring Your Favorite Actions – PlanetOzh […]

  7. […] the users themselves choose what goes into this quick-access menu (incidentally, Ozh has proposed something similar). It wouldn't be realistic to devise a "one size fits all" list of defaults, and […]

  8. […] Bu menüye yeni seçenekler eklemek ister miydiniz? Cevab?n?z evet ise sa?olsun Ozh'un sitesinde bahsetti?i basit bir yöntemle kolayl?kla yeni seçenekler ekleyebiliyor ya da mevcutlar? […]

  9. […] WordPress 2.7 Featuring Your Favorite Actions – PlanetOzh, […]

  10. […] For further reading, see Ozh's little write-up of the favorite_actions hook. […]

  11. redwall_hp says:

    You wanted a plugin? Here it is, fresh from the code forges:

  12. Matt Martz says:

    I'll throw mine in here too. It has been a while since completion, and after reading your post I decided to sit down and hash out a dynamic favorites menu plugin.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?