Adding a Link to the WordPress 2.7 Favorites Dropdown

There was some concern on the WP-Hackers list that the sidemenu action had been removed from WordPress 2.7. As the “sidemenu” (Settings, Plugins, Users) links no longer exist in 2.7 this action was removed. There is, however a suitable replacement which is the favorites dropdown.

This code snippet will show you what is required to add a link to the favorites dropdown.

<?php
function add_to_favorites( $favorites_array ) {
       $favorites_array['link-add.php'] = array('Add Link', 'manage_links');
       return $favorites_array;
}

add_filter('favorite_actions', 'add_to_favorites');
?>

I’ll break down the line where we insert an element into the array so it makes more sense:

$favorites_array['link-add.php'] = array('Add Link', 'manage_links');

We want to insert a new key into the array where the key is the href for the link. In this case I just made it ‘link-add.php’ but could be anything like ‘options.php’ or ‘admin.php?page=my-plugins-options-page’.

The value for that key is an array where the first element is the display text and the second is the minimum user role required to see that link in the favorites.

Use this responsibly. Plugin authors, please do not go adding tons of useless crap to the favorites menu, use this only when it makes sense.

Enjoy!

About Matt

IF YOU REALLY want to hear about it, the first thing you'll probably want to know is where I was born, and what my lousy childhood was like, and how my parents were occupied and all before they had me, and all that David Copperfield kind of crap, but I don't feel like going into it, if you want to know the truth.

In any case I am employed as a Senior Linux Systems Engineer at Rackspace in San Antonio, TX.

I spent the majority of my college years as an Astrophysics major specializing in black holes. When I got to my senior year and was studying 40 hours a week to stay on track I decided to bail and pursue an easier career.

I spend the majority of my time now contributing to WordPress, developing WordPress plugins, helping out in the WordPress IRC Channel, playing football (not American!), practicing Krav Maga, and last but not least, spending time with my Wife and Son.

This entry was posted in Code, PHP, Snippet, WordPress. Bookmark the permalink.

One Response to Adding a Link to the WordPress 2.7 Favorites Dropdown

  1. Pingback: Plugins and 2.7: Using the Favorite Actions Menu Responsibly | HolisticNetworking.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre>