Skip to content

Instantly share code, notes, and snippets.

@nielslange

nielslange/stats.js

Last active Apr 18, 2020
Embed
What would you like to do?
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 ));
for ( plugin of plugins ) {
downloads += plugin['downloaded'];
installs += plugin['active_installs'];
console.log( plugin['name'] + " had been downloaded " + plugin['downloaded'] + " and installed " + plugin['active_installs'] + " times." );
}
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
You can’t perform that action at this time.