Skip to content Skip to tags Skip to twitter news Skip to blog roll Skip to categories Skip to archives Skip to recent posts

November 22, 2008

1 Comment

New Favorite Actions in WordPress 2.7

by in Tips,Wordpress on November 22, 2008 @ 12:43 pm
New favorite actions dropdown (favorite_actions)

WordPress 2.7 will be release sometime soon and with it comes a new feature call “favorite actions,” it’s a drop down menu that is sort of a quick launch to your most used actions. Right now it only contains “Add New Post”, “Add New Page” and “Manage Comments”. Like with most features in WordPress, you can easily add to via the “add_filter” function link so:

  1. add_filter('favorite_actions', 'new_favorite_actions');

The new function that builds out that drop down menu is called “favorite_actions” and is located in the “/wp-admin/includes/template.php” file.  The default menu structure array is below:

  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 first part of the array “post-new.php” is of course the page it will be going to, the second page is an array with the text that would be shown in the menu and the permission.  Have a look-see at roles and capabilities on the WordPress site for more information about permission.

Although I don’t see a way to add favorite actions on the fly there is a way to add some via a plugin.  In my PhotoXhibit plugin I will be using the following code to add menu options for adding a new gallery and for managing galleries.

  1. $newactions = array(
  2.     'admin.php?page=px_build' => array(__('Add New Gallery'), 'level_10'),
  3.     'admin.php?page=px_manage' => array(__('Manage Galleries'), 'level_10')
  4.     );
  6. return array_merge($actions, $newactions);

Notice how I am adding to the $action array, I am using the array_merge which does exactly what it says, it merges the two arrays.

A Plugin

Below is a basic plugin template that you can use to add your own menu items to the favorite menu.

  1. <?php
  2. /*
  3. Plugin Name: A Favorite Menu Action Plugin Template
  4. Plugin URI:
  5. Description: This is a templete for you to build your own plugin
  6. Author: Benjamin Sterling
  7. Author URI:
  8. */
  9. add_filter('favorite_actions', 'bs_template_for_favorite');
  10. function bs_template_for_favorite($actions) {
  11.     $newactions = array(
  12.         'admin.php?page=pluginshortcut/plugin.php' => array(__('Some plugin'), 'manage_options'),
  13.         'upload.php' => array(__('Manage Library'), 'edit_files')
  14.         );
  16.     return array_merge($actions, $newactions);
  17. }
  18. ?>

Final thoughts

Although the new “favoriate_actions” function is nice and the favorite menu does what it needs to do, I am a bit nervous that plugin developers will not give their users the option to add to it and just force it upon them.  Which may not be an issue but what if you twenty plugins that all force their items in to the favorite list?  Or what if a plugin developer clears out the initial action array and puts in only their plugin URI?  It can get to be a bit hairy.

I would also say that this new feature can become quite powerful and useful.  What if someone comes up with a plugin, or WordPress institutes a feature, that tracks the pages you use most often and adds those pages to the list.  Or what about a plugin that attaches itself to the option area and has a checkbox for every admin page/action and you can click to add all the favs you want?  Any takers?

back to beginning of this post back to skip to links
Tags: ,

If you liked this article why don't you share it:

Stumble it delicious Digg it Reddit it DZone it Bump it Mixx it! Buzz up! E-mail

One Response to “New Favorite Actions in WordPress 2.7”

Very cool. I’ll have to try that out.

Learn from my mistakes, I got burnt by the flame, you don't have to.

RSS Feed Link My Hosting of Choice

70 queries. 0.409 seconds. Powered by WordPress visitor stats