Skip to main content
1 of 3
birgire
  • 67.8k
  • 7
  • 119
  • 251

Here is one idea:

You always have the possibility to scrape the plugin's download html page:

http://wordpress.org/extend/plugins/some-plugin-slug/stats/

while you don't have any json/xml/rss sources with the today's download counter.

The html part you are interested in has this form:

<div id="history" class="left">
<h4>History</h4>
<table>
    <tr>
        <th scope="row">Today</th>
        <td>7,390</td>
    </tr>

    <tr>
        <th scope="row">Yesterday</th>
        <td>12,262</td>
    </tr>

    <tr>
        <th scope="row">Last Week</th>
        <td>130,130</td>
    </tr>

    <tr class="last-child">
        <th scope="row">All Time</th>
        <td>13,639,901</td>
    </tr>
</table>
</div>

You could use wp_remote_get() and cache the results.

Here is a function to fetch the data:

function get_todays_downloads($url){    
    $downloads_today="?";
    $response = wp_remote_get( $url );
    if( is_wp_error( $response ) ) {
       $error_message = $response->get_error_message();
       echo "Something went wrong:". $error_message;
    } else {
        
        // get the body of the page:
        //
        $html=$response['body'];

        // let's strip out the newlines and tabs:
        //
        $html=str_replace("\n","",$html);
        $html=str_replace("\t","",$html);
       
            // let's find this type of html string:
            //    Today</th><td>12</td></tr>
        //
        preg_match('/Today<\/th><td>([0-9,]+)<\/td><\/tr>/i', $html, $matches);

        // check if we got a match:
            //
            if(isset($matches[1])){
            $downloads_today=$matches[1];
        }
    }
    return $downloads_today;        
}

You can use it like this:

// plugin's stats url:
$url="http://wordpress.org/extend/plugins/akismet/stats/";
echo "Downloads today: ".get_todays_downloads($url);

and it will give you results like:

 Downloads today: 7,397

Just remember that the html of the page can change in the future ;-)

birgire
  • 67.8k
  • 7
  • 119
  • 251