The favorited plugins has been added to the WordPress.org API. There is a new feature in 3.5 that allows you to access your favorites from the plugin installer.
See http://core.trac.wordpress.org/ticket/22002 for info on how it is being used in core.
The API allows you to retrieve an object that contains contains each plugins
- name
- description
- author
- rating
- last updated date
- change log
- stable version
- works with wp version
To retrieve the object
Make a call to http://api.wordpress.org/plugins/info/1.0/ using wp_remote_post passing an array of arguments including the action which would be 'query_plugins' and the wp dot org username to retrieve the favorites from.
$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) );
Before you have a nice clean object you need to do some error handling and other parsing. Here is an example function that will return a nice clean object holding all the plugin details.
function api( $action, $args ) {
if ( is_array( $args ) )
$args = (object) $args;
$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) );
if ( is_wp_error($request) ) {
$res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
} else {
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
if ( ! is_object( $res ) && ! is_array( $res ) )
$res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
}
return apply_filters( 'c3m_favorite_results', $res, $action, $args );
}
Usage
This example usage will give you an unordered list of favorite plugins along with a link to the plugin on dot org, a link to the author uri and the star rating.
$api_data = api( 'query_plugins', array( 'user' => 'my_dot_org_username' ) );
$api_plugins = $api_data->plugins;
echo '<ul class="c3m-favorites">';
foreach( $api_plugins as $plugin ) {
$name = $plugin->name; ?>
<li><strong><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $plugin->slug ?>/"><?php echo esc_html( $name ); ?></a></strong><br>
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin->num_ratings ), number_format_i18n( $plugin->num_ratings ) ); ?>">
<div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin->rating ) ); ?>px"></div></div>
<em><?php _e('By: ') ?></em> <?php echo links_add_target( $plugin->author, '_blank' ). '<br>'; ?>
</li><?php
}
echo '</ul>';
Result
Widget screenshot from my Favorite Plugins Widget plugin:
http://wordpress.org/extend/plugins/favorite-plugins-widget/
div.star-holder .star-rating
selectors and serving those from the plugin style sheet. Make sure you copy the star rating background image over too. Then, when you scrape the<div class="star-rating" style="width:??px"></div>
element, your css property will output the display of stars (whatever their rating) since it's controlled by the width of thediv
. Easy peasy.