Last active
October 15, 2016 15:08
-
-
Save rubelmiah/5f6ed277643d5fc5f7b9be04b3fdb246 to your computer and use it in GitHub Desktop.
How to Total Download Count For Plugins on WordPress.org Username
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
<?php | |
// Add this code in your functions.php file. | |
function rm_total_download( $username = false, $args = array() ) { | |
if( $username ) { | |
$params = array( | |
'timeout' => 10, | |
'sslverify' => false | |
); | |
$raw = wp_remote_retrieve_body( wp_remote_get( 'http://wptally.com/api/' . $username, $params ) ); | |
$raw = json_decode( $raw, true ); | |
if( array_key_exists( 'error', $raw ) ) { | |
$tally = array( | |
'error' => $raw['error'] | |
); | |
} else { | |
$tally = $raw; | |
} | |
} else { | |
$tally = array( | |
'error' => __( 'No username has been specified!', 'rubel-miah' ) | |
); | |
} | |
return apply_filters( 'rm_total_download', $tally ); | |
} | |
// Add this code for count total number. | |
// Type your wordpress.org username "rubel_miah" | |
$total_downloads = rm_total_download('rubel_miah'); | |
if( array_key_exists( 'error', $total_downloads ) ) { | |
echo esc_html($total_downloads['error']); | |
} else { | |
foreach($total_downloads as $total_download){ | |
echo $total_download['total_plugin_downloads']; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment