In: , ,
On: 2008 / 10 / 27 Viewed: 15854 times

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:

PHP:
  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:

PHP:
  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?

Related posts

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. You can trackback this post from your own site

11 Blablas

    Pages: [2] 1 » Show All

  1. 11
    redwall_hp United States »
    wrote, 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/

Pages: [2] 1 » Show All

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 ?

Close
E-mail It