true, 'rating' => false, 'description' => false, 'short_description' => false, 'donate_link' => false, 'tags' => false, 'sections' => false, 'homepage' => true, 'added' => false, 'last_updated' => false, 'compatibility' => false, 'tested' => false, 'requires' => false, 'downloadlink' => false, ); $args = (object) array( 'author' => $author, 'fields' => $fields ); $request = array( 'action' => 'query_plugins', 'timeout' => 15, 'request' => serialize( $args) ); $response = wp_remote_post( $url, array( 'body' => $request ) ); $plugins_info = unserialize( $response['body'] ); $result = array(); $total_dl = ''; $total_avg = ''; if ( isset( $plugins_info ) ) { # let's build our array of data to return foreach ($plugins_info->plugins as $plugin) { $pl_name = $plugin->slug; $pl_dirlink = 'https://wordpress.org/plugins/' . $pl_name; $pl_icon = 'https://ps.w.org/' . $pl_name . '/assets/icon-256x256.png'; $pl_download = $plugin->download_link; $pl_downloaded = $plugin->downloaded; $pl_home = $plugin->homepage; $pl_voters = $plugin->num_ratings; $pl_stars = $plugin->ratings; $avg_vote = ($pl_stars[1] + $pl_stars[2] * 2 + $pl_stars[3] * 3 + $pl_stars[4] * 4 + $pl_stars[5] * 5) / $pl_voters; $pl_avg_vote = ( ! is_int($avg_vote) ? 0 : $avg_vote ); $total_dl += $pl_downloaded; $total_avg += $pl_avg_vote; $result[$pl_name] = array( 'dir_link' => $pl_dirlink, 'dl_link' => $pl_download, 'home_link' => $pl_home, 'icon' => $pl_icon, 'downloaded' => $pl_downloaded, 'voters' => $pl_voters, 'avg_rating' => $pl_avg_vote ); } $avg = $total_avg / count($plugins_info->plugins); $result['total_plugins'] = count($plugins_info->plugins); $result['total_downloads'] = $total_dl; $result['average_rating'] = round( $avg, 2); return $result; } return array(); } /** * This function will execute with the scheduled cron job and update the data inside the option * @since 0.1 */ function dnxwporg_save_plugins_stats() { $author = get_option('dnxwporg_author'); $plugins = dnxwporg_get_plugins_stats( $author ); update_option( 'dnxwporg_plugins_stats', $plugins ); } add_action( 'dnxwporg_save_plugins_stats', 'dnxwporg_save_plugins_stats' ); /** * we schedule the cron if it's not yet scheduled * @since 0.1 */ if ( ! wp_next_scheduled( 'dnxwporg_save_plugins_stats' ) ) { wp_schedule_event( 1407110400, 'daily', 'dnxwporg_save_plugins_stats' ); // 1407110400 is 08 / 4 / 2014 @ 0:0:0 UTC } /** * Add function to widgets_init that'll load our widget. * @since 0.1 */ add_action( 'widgets_init', 'danixland_wporg_widget' ); /** * Register our widget. * 'dnx_WPOrg' is the widget class used below. * * @since 0.1 */ function danixland_wporg_widget() { register_widget( 'dnx_WPOrg' ); } /** * dnx_WPOrg class. * This class handles everything that needs to be handled with the widget: * the settings, form, display, and update. Nice! * * @since 0.1 */ class dnx_WPOrg extends WP_Widget { /** * Widget setup. */ public function __construct() { parent::__construct( 'danixland-wporg-stats', __( 'danixland WP.org Stats', 'dnxwporg' ), array( 'customize_selective_refresh' => true, 'description' => __('Use this widget to display statistics about your WP.org hosted plugins on your site', 'dnxwporg'), ) ); } /** * Displays the setup form for the widget in the widgets page */ public function form( $instance ) { $defaults = array( 'title' => __( 'WP.org Plugins Stats', 'dnxwporg' ), 'author' => get_option( 'dnxwporg_author' ), 'description' => get_option( 'dnxwporg_description' ), 'desc_content' => get_option( 'dnxwporg_desc_content' ), 'link_wporg' => get_option( 'dnxwporg_linkto' ), 'use_icons' => get_option( 'dnxwporg_use_icons' ) ); $instance = wp_parse_args( (array) $instance, $defaults ); extract( $instance, EXTR_SKIP ); ?>

id="dnxwporg_use_desc" name="get_field_name( 'description' ); ?>" />

id="get_field_id( 'link_wporg' ); ?>" name="get_field_name( 'link_wporg' ); ?>" />

id="get_field_id( 'use_icons' ); ?>" name="get_field_name( 'use_icons' ); ?>" />

%s plugin with %s total downloads and an average rating of %s', '%s contributed %s plugins with %s total downloads and an average rating of %s', $plugins['total_plugins'], 'dnxwporg' ), $author, $plugins['total_plugins'], $plugins['total_downloads'], $plugins['average_rating'] ); ?>