Skip to content

Instantly share code, notes, and snippets.

@nielslange
Last active May 14, 2022 08:23
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 nielslange/a3931bf2a9722af2d8a505cc442f847d to your computer and use it in GitHub Desktop.
Save nielslange/a3931bf2a9722af2d8a505cc442f847d to your computer and use it in GitHub Desktop.
Fetch total downloads and installs of all WordPress plugins
let url = 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[fields][banners]=true&request[search]=SMNTCS';
let downloads = 0;
let installs = 0;
let plugins;
let plugin;
fetch( url )
.then( response => {
return response.json()
} )
.then( data => {
plugins = data['plugins'];
// plugins.sort((a, b) => a.name.localeCompare(b.name)); // Sort by plugin name
// plugins.sort( ( a, b ) => a.downloaded < b.downloaded ? 1 : -1 )); // Sort by downloads
plugins.sort((a, b) => (a.tested < b.tested ? 1 : -1)); // Sort by downloads
for ( plugin of plugins ) {
downloads += plugin['downloaded'];
installs += plugin['active_installs'];
console.log( plugin['name'] + " had been downloaded " + plugin['downloaded'] + ", installed " + plugin['active_installs'] + " times and tested up to " + plugin['tested'] + "." );
}
console.log( "All plugins have been downloaded " + downloads + " and installed " + installs + " times." );
} )
.catch(err => {
console.log( err );
} )
// Fetching stats for one plugin:
// @see https://developer.wordpress.org/reference/functions/plugins_api/
// https://api.wordpress.org/plugins/info/1.0/smntcs-google-webmaster-tools.json
// Fetching stats for all themes:
// @see https://developer.wordpress.org/reference/functions/themes_api/
// https://api.wordpress.org/themes/info/1.2/?action=query_themes&request[search]=SMNTCS&request[fields][downloaded]=true&request[fields][active_installs]=true
// Fetching all open PRs from Github
// https://api.github.com/search/issues?q=state:open+author:nielslange+type:pr
// Fetching all closed PRs from Github
// https://api.github.com/search/issues?q=state:closed+author:Anielslange+type:Apr
// Fetching all merged PRs from Github
// https://api.github.com/search/issues?q=state:closed+author:nielslange+type:pr+is:merged
// Fetching all open issues from Github
// https://api.github.com/search/issues?q=state:open+author:nielslange+type:issue
// Fetching all closed issues from Github
// https://api.github.com/search/issues?q=state:closed+author:nielslange+type:issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment