'blog-stats', 'description' => esc_html__( 'Show a hit counter for your blog.', 'jetpack' ), 'customize_selective_refresh' => true, ); parent::__construct( 'blog-stats', /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', esc_html__( 'Blog Stats', 'jetpack' ) ), $widget_ops ); $this->alt_option_name = 'widget_statscounter'; } /** * Return an associative array of default values * * These values are used in new widgets. * * @return array Array of default values for the Widget's options */ public function defaults() { return array( 'title' => esc_html__( 'Blog Stats', 'jetpack' ), /* Translators: Number of views, plural */ 'hits' => esc_html__( 'hits', 'jetpack' ), ); } /** * Return All Time Stats for that blog. * * We query the WordPress.com Stats REST API endpoint. * * @uses stats_get_from_restapi(). That function caches data locally for 5 minutes. * * @return string|false $views All Time Stats for that blog. */ public function get_stats() { // Get data from the WordPress.com Stats REST API endpoint. $stats = stats_get_from_restapi( array( 'fields' => 'stats' ) ); if ( isset( $stats->stats->views ) ) { return $stats->stats->views; } else { return false; } } /** * Back end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @return void */ function form( $instance ) { $instance = wp_parse_args( $instance, $this->defaults() ); ?>
defaults() ); /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } // Get the Site Stats. $views = $this->get_stats(); if ( ! empty( $views ) ) { printf( '