Skip to content

Instantly share code, notes, and snippets.

@stephenh1988
Created July 2, 2012 16:55
Show Gist options
  • Save stephenh1988/3034246 to your computer and use it in GitHub Desktop.
Save stephenh1988/3034246 to your computer and use it in GitHub Desktop.
Function to retrieve an array of (WordPress hosted) plug-ins by a particular author, given by their WordPress repository username
<?php
/**
* Function to retrieve an array of (WordPress hosted) plug-ins by a particular author, given by their WordPress repository username.
*
* For information on using the WordPress API see the wptuts tutorial: (link to follow)
*
*
* @param author - WordPress username
* @param fields - which fields (plug-in details) to return. See tutorial for details.
*/
function sh_get_plugins_by_author($author='', $fields=array('downloaded'=>true,'downloadlink'=>true)){
if( empty($author) )
return false;
$key = sanitize_key('sh_plugins_'.$author);
if (false === ( $plugins = get_transient($key) ) ){
$args = array('author'=>$author, 'fields'=>$fields);
$response = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array(
'body' => array(
'action' => 'query_plugins',
'request' => serialize((object)$args)
)
));
$plugin_response = unserialize(wp_remote_retrieve_body($response));
$plugins = $plugin_response->plugins;
//Set transient for next time... keep it for 24 hours should be good
set_transient($key, $plugins, 60*60*24);
}
return $plugins;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment