Grab WordPress plugin downloads counter from plugin page on wordpress.org

/**
 * Get WordPress plugin downloads counter.
 * Usage example: echo get_plugin_downloads_counter( 'woocommerce' );
 * @return mixed: numeric counter on success, boolean false otherwise
 */
function get_plugin_downloads_counter( $plugin_slug ) {
	if ( false !== ( $html = file_get_contents( 'http://wordpress.org/plugins/' . $plugin_slug . '/' ) ) ) {
		if ( preg_match( '/"UserDownloads:(?P<digit>\d+)"/', $html, $matches ) ) {
			return ( isset( $matches['digit'] ) ) ? $matches['digit'] : false;
		}
	}
	return false;
}

No comments yet.

Leave a Reply