Fetch total downloads and installs of all WordPress plugins
let url = 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&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 );
} )