BBP_Stats_Widget

BbPress Stats Widget.

Defined (1)

The class is defined in the following location(s).

/includes/common/widgets.php  
  1. class BBP_Stats_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * bbPress Stats Widget 
  5. * Registers the stats widget 
  6. * @since bbPress (r4509) 
  7. * @uses apply_filters() Calls 'bbp_stats_widget_options' with the 
  8. * widget options 
  9. */ 
  10. public function __construct() { 
  11. $widget_ops = apply_filters( 'bbp_stats_widget_options', array( 
  12. 'classname' => 'widget_display_stats',  
  13. 'description' => __( 'Some statistics from your forum.', 'bbpress' ) 
  14. ) ); 
  15.  
  16. parent::__construct( false, __( '(bbPress) Statistics', 'bbpress' ), $widget_ops ); 
  17.  
  18. /** 
  19. * Register the widget 
  20. * @since bbPress (r4509) 
  21. * @uses register_widget() 
  22. */ 
  23. public static function register_widget() { 
  24. register_widget( 'BBP_Stats_Widget' ); 
  25.  
  26. /** 
  27. * Displays the output, the statistics 
  28. * @since bbPress (r4509) 
  29. * @param mixed $args Arguments 
  30. * @param array $instance Instance 
  31. * @uses apply_filters() Calls 'bbp_stats_widget_title' with the title 
  32. * @uses bbp_get_template_part() To get the content-forum-statistics template 
  33. */ 
  34. public function widget( $args = array(), $instance = array() ) { 
  35.  
  36. // Get widget settings 
  37. $settings = $this->parse_settings( $instance ); 
  38.  
  39. // Typical WordPress filter 
  40. $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 
  41.  
  42. // bbPress widget title filter 
  43. $settings['title'] = apply_filters( 'bbp_stats_widget_title', $settings['title'], $instance, $this->id_base ); 
  44.  
  45. echo $args['before_widget']; 
  46.  
  47. if ( !empty( $settings['title'] ) ) { 
  48. echo $args['before_title'] . $settings['title'] . $args['after_title']; 
  49.  
  50. bbp_get_template_part( 'content', 'statistics' ); 
  51.  
  52. echo $args['after_widget']; 
  53.  
  54. /** 
  55. * Update the stats widget options 
  56. * @since bbPress (r4509) 
  57. * @param array $new_instance The new instance options 
  58. * @param array $old_instance The old instance options 
  59. * @return array 
  60. */ 
  61. public function update( $new_instance, $old_instance ) { 
  62. $instance = $old_instance; 
  63. $instance['title'] = strip_tags( $new_instance['title'] ); 
  64.  
  65. return $instance; 
  66.  
  67. /** 
  68. * Output the stats widget options form 
  69. * @since bbPress (r4509) 
  70. * @param $instance 
  71. * @return string|void 
  72. */ 
  73. public function form( $instance ) { 
  74.  
  75. // Get widget settings 
  76. $settings = $this->parse_settings( $instance ); ?> 
  77.  
  78. <p> 
  79. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 
  80. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>"/> 
  81. </label> 
  82. </p> 
  83.  
  84. <?php 
  85.  
  86. /** 
  87. * Merge the widget settings into defaults array. 
  88. * @since bbPress (r4802) 
  89. * @param $instance Instance 
  90. * @uses bbp_parse_args() To merge widget settings into defaults 
  91. */ 
  92. public function parse_settings( $instance = array() ) { 
  93. return bbp_parse_args( $instance, array( 
  94. 'title' => __( 'Forum Statistics', 'bbpress' ) 
  95. ),  
  96. 'stats_widget_settings' );