I’m really excited about a new feature that is coming in WordPress 3.5 – plugin favorites as an extra tab from the “Add New” plugins page. The WordPress Plugin Favorites API is utilized to process this, and luckily for us, we can utilize it ourselves as well!
What Are Plugin Favorites?
If you hadn’t noticed previously, you can now favorite plugins listed in the official WordPress Plugin Repository. This is essentially a bookmarking mechanism for displaying the plugins that you use most often, e.g. your “plugin favorites”.
Until now, plugin favorites had been little more than a bookmarking mechanism with no real use. Now that the Plugin Favorites API has been introduced, it has some awesomely good implications for those that take advantage of it.
For starters, the API will be introduced into core so that you can easily search for your favorites straight from the Plugins area to install. No more searching around or endlessly typing out all the plugins that you use on a regular basis – a huge win for developers and users alike.
Using the Plugin Favorites API
Getting data via the Plugin Favorites API is quite easy actually. We can use a function baked into WordPress,
plugins_api, to get our favorites with easy. Here’s how you do it (quick and dirty to get the favorites data):
We make sure that
plugins_api is available, prepare the query and then print our the results on our screen. If there is an error, we display the error message; else an object will be returned with all the plugin favorites data for the particular username that you have entered. I’ve included my own username in this particular query, so feel free to change it to your username if you want to see your plugin favorites displayed on the screen. The results you receive should look something similar to this:
From here you can loop through the plugins key and display data, like this:
..and so on and so forth.
**Note that the API is still in development and may change some before 3.5 is released. I’ll make sure to keep watch and update this post if/when that occurs.
The Plugin Favorites API is a sweet addition to WordPress and I am excited to see how it will be used in future plugins and applications!