In: , ,
On: 2008 / 10 / 27 Viewed: 56116 times
Shorter URL for this post: http://ozh.in/je

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.

Concept

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: http://planetozh.com/blog/
  5. Description: Example plugin showing how to modify the favorite actions
  6. Author: Ozh
  7. Author URI: http://planetozh.com/
  8. */
  9.  
  10. add_filter('favorite_actions', 'ozh_sample_fav');
  11.  
  12. function ozh_sample_fav($actions) {
  13.     // remove the "Add new page" link
  14.     unset($actions['page-new.php']);
  15.     // add quick link to our favorite plugin
  16.     $actions['admin.php?page=blah/blah.php'] = array('Some plugin', 'manage_options');
  17.     return $actions;
  18. }
  19.  
  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: http://ozh.in/je

Metastuff

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. 1
    James Dimick United States »
    wrote, on 27/Oct/08 at 6:41 pm # :

    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. 2
    Ozh France »
    commented, on 28/Oct/08 at 12:00 am # :

    James » My pleasure ! :)

  3. 3
    WordPress Favorite Actions and Custom Wr... United States »
    pingback on 28/Oct/08 at 9:59 pm # :

    [...] 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. 4
    modbo Germany »
    replied, on 29/Oct/08 at 8:25 pm # :

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

  5. 5
    Fujilives United States »
    commented, on 29/Oct/08 at 10:50 pm # :

    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. 6
    Wordpress 2.7 - Emmanuel GEORJON Germany »
    pingback on 31/Oct/08 at 9:01 am # :

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

  7. 7
    ø Custom Favorite Actions For WP 2.7 (B... United States »
    pingback on 31/Oct/08 at 7:24 pm # :

    [...] 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. 8
    WordPress 2.7 Favori ??lemler · Y... Turkey »
    pingback on 04/Nov/08 at 2:53 pm # :

    [...] 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. 9
    WordPress 2.7 RC1 - Emmanuel GEORJON Germany »
    pingback on 02/Dec/08 at 1:02 pm # :

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

  10. 10
    Add An Item to WordPress 2.7’s Fav... United States »
    pingback on 28/Dec/08 at 11:24 pm # :

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

  11. 11
    redwall_hp United States »
    replied, on 02/Jan/09 at 11:52 pm # :

    You wanted a plugin? Here it is, fresh from the code forges: http://wordpress.org/extend/plugins/favorites-menu-manager/

  12. 12
    Matt Martz United States »
    commented, on 24/Feb/09 at 2:44 am # :

    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.

    http://sivel.net/2009/01/dynamic-favorites/

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?