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:
- $actions = array(
- 'post-new.php' => array(__('Add New Post'), 'edit_posts'),
- 'page-new.php' => array(__('Add New Page'), 'edit_pages'),
- 'edit-comments.php' => array(__('Manage Comments'), 'moderate_comments')
- );
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
- /*
- Plugin Name: Sample Favorite Actions
- Plugin URI: http://planetozh.com/blog/
- Description: Example plugin showing how to modify the favorite actions
- Author: Ozh
- Author URI: http://planetozh.com/
- */
- add_filter('favorite_actions', 'ozh_sample_fav');
- function ozh_sample_fav($actions) {
- // remove the "Add new page" link
- unset($actions['page-new.php']);
- // add quick link to our favorite plugin
- $actions['admin.php?page=blah/blah.php'] = array('Some plugin', 'manage_options');
- return $actions;
- }
- ?>
(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
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:
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!
James » My pleasure ! :)
[…] 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? […]
Thank you for the useful WordPress hints. You've made very good enquiries.
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?
[…] WordPress 2.7 Featuring Your Favorite Actions – PlanetOzh […]
[…] 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 […]
[…] 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? […]
[…] WordPress 2.7 Featuring Your Favorite Actions – PlanetOzh, […]
[…] For further reading, see Ozh's little write-up of the favorite_actions hook. […]
You wanted a plugin? Here it is, fresh from the code forges: http://wordpress.org/extend/plugins/favorites-menu-manager/
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/