Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Get Plugin Data from WordPress.org
- *
- * Uses WP API : http://wpapi.org/
- * Function extracted from Viper007Bond's plugin: http://wordpress.org/extend/plugins/wordpress-download-counter/
- * Usage: change $plugin_url value and adapt the result to your code
- *
- */
- function get_data() {
- // CHANGE THIS TO YOUR OWN PLUGIN URL, this is mine :)
- $plugin_url = 'http://wpapi.org/api/plugin/many-tips-together.json';
- // Check for a cached copy (we don't want to do an HTTP request too often)
- $cachetime = 15; // Seconds between AJAX powered refreshes
- $cache = get_transient('wpdlcounter');
- if ( false !== $cache )
- return $cache;
- $data = array();
- // Fetch the data
- if ( $response = wp_remote_retrieve_body( wp_remote_get( $plugin_url ) ) ) {
- // Decode the json response
- if ( $response = json_decode( $response, true ) ) {
- // Double check we have all our data
- if ( !empty($response['added']) ) {
- $data = $response;
- }
- }
- }
- // On a failed scrape, cache that fail for a full minute
- else {
- set_transient( 'wpdlcounter', $data, 60 );
- }
- // Cache the data for future usage
- if ( $cachetime < 2 )
- $cachetime = 2;
- set_transient( 'wpdlcounter', $data, $cachetime - 1 );
- return $data;
- }
- $my_plugin = get_data();
- echo 'Total Downloads: ' . number_format_i18n($my_plugin['total_downloads']);
- echo 'Rating: ' . $my_plugin['rating'];
- echo 'Total ratings: ' . number_format_i18n($my_plugin['num_ratings']);
- echo 'Updated: ' . date_i18n(get_option('date_format'), strtotime($my_plugin['updated']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement