Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active June 5, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/14bf8bbcee5f2da6285efd312d965a5b to your computer and use it in GitHub Desktop.
Save cliffordp/14bf8bbcee5f2da6285efd312d965a5b to your computer and use it in GitHub Desktop.
Get your WordPress.org favorite plugins
<?php
/**
* Get your WordPress.org favorite plugins.
*
* Set a breakpoint or var_dump() within plugins_api() at `if ( is_wp_error( $request ) ) {` to see the URL. Example:
* https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[user]=cliffpaulick&request[per_page]=250&request[fields][description]=0&request[fields][tested]=0&request[fields][requires]=0&request[fields][rating]=0&request[fields][ratings]=0&request[fields][downloaded]=0&request[fields][downloadlink]=0&request[fields][added]=0&request[fields][donate_link]=0&request[fields][icons]=0&request[locale]=en_US&request[wp_version]=5.2
*
* @link https://developer.wordpress.org/reference/functions/plugins_api/
*
* @see \plugins_api()
*
* @return string Nothing really. Need to set a breakpoint or add var_dump() in plugins_api() to get the request URL.
*/
function cliff_favs_plugins_from_wordpress_org() {
if ( ! current_user_can( 'install_plugins' ) ) {
return '';
}
if ( ! function_exists( 'plugins_api' ) ) {
// Local by Flywheel
require_once( '/app/public/wp-admin/includes/plugin-install.php' );
}
$args = [
'user' => 'cliffpaulick', // @TODO: Change this!
'per_page' => 250, // max allowed by the API
'fields' => [ // Declutter the response, since we just want to look/find through the results
'description' => false,
'tested' => false,
'requires' => false,
'rating' => false,
'ratings' => false,
'downloaded' => false,
'downloadlink' => false,
'added' => false,
'donate_link' => false,
'icons' => false,
],
];
$api = plugins_api( 'query_plugins', $args );
// Set a breakpoint or var_dump() within plugins_api() at `if ( is_wp_error( $request ) ) {` to see the URL.
return '';
}
add_action( 'admin_init', 'cliff_favs_plugins_from_wordpress_org', 50 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment