Last active
February 20, 2020 11:06
-
-
Save roborourke/bc2a677e46638f1e9df8923cc88622e3 to your computer and use it in GitHub Desktop.
Get stats from packagist for all WP related packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$plugins = file_get_contents( 'https://packagist.org/packages/list.json?type=wordpress-plugin' ); | |
$muplugins = file_get_contents( 'https://packagist.org/packages/list.json?type=wordpress-muplugin' ); | |
$dropins = file_get_contents( 'https://packagist.org/packages/list.json?type=wordpress-dropin' ); | |
$themes = file_get_contents( 'https://packagist.org/packages/list.json?type=wordpress-theme' ); | |
$plugins_json = json_decode( $plugins, true )['packageNames']; | |
$muplugins_json = json_decode( $muplugins, true )['packageNames']; | |
$dropins_json = json_decode( $dropins, true )['packageNames']; | |
$themes_json = json_decode( $themes, true )['packageNames']; | |
echo sprintf( | |
"Plugins: %d\nMU Plugins: %d\nDropins: %d\nThemes: %d\n\n", | |
count( $plugins_json ), | |
count( $muplugins_json ), | |
count( $dropins_json ), | |
count( $themes_json ) | |
); | |
$all = array_merge( | |
$plugins_json, | |
$muplugins_json, | |
$dropins_json, | |
$themes_json, | |
// Add popular WP installer composer plugins. | |
[ 'johnpbloch/wordpress', 'fancyguy/webroot-installer' ] | |
); | |
$total = 0; | |
$monthly = 0; | |
$daily = 0; | |
foreach ( $all as $package ) { | |
$package_data = file_get_contents( "https://packagist.org/packages/{$package}.json" ); | |
$package_json = json_decode( $package_data, true ); | |
$total += $package_json['package']['downloads']['total']; | |
$monthly += $package_json['package']['downloads']['monthly']; | |
$daily += $package_json['package']['downloads']['daily']; | |
} | |
echo sprintf( | |
"Downloads:\nTotal: %s\nMonthly: %s\nDaily: %s\n", | |
number_format( $total ), | |
number_format( $monthly ), | |
number_format( $daily ) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output on 23rd Jan 2020: