BBP_Stats_Widget
bbPress Statistics Widget
Description Description
Adds a widget which displays the forum statistics
Source Source
File: includes/common/widgets.php
class BBP_Stats_Widget extends WP_Widget {
/**
* bbPress Statistics Widget
*
* Registers the statistics widget
*
* @since 2.3.0 bbPress (r4509)
*/
public function __construct() {
$widget_ops = apply_filters( 'bbp_stats_widget_options', array(
'classname' => 'widget_display_stats',
'description' => esc_html__( 'Some statistics from your forum.', 'bbpress' ),
'customize_selective_refresh' => true
) );
parent::__construct( false, esc_html__( '(bbPress) Statistics', 'bbpress' ), $widget_ops );
}
/**
* Register the widget
*
* @since 2.3.0 bbPress (r4509)
*/
public static function register_widget() {
register_widget( 'BBP_Stats_Widget' );
}
/**
* Displays the output, the statistics
*
* @since 2.3.0 bbPress (r4509)
*
* @param array $args Arguments
* @param array $instance Instance
*/
public function widget( $args = array(), $instance = array() ) {
// Get widget settings
$settings = $this->parse_settings( $instance );
// Typical WordPress filter
$settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
// bbPress widget title filter
$settings['title'] = apply_filters( 'bbp_stats_widget_title', $settings['title'], $instance, $this->id_base );
echo $args['before_widget'];
if ( ! empty( $settings['title'] ) ) {
echo $args['before_title'] . $settings['title'] . $args['after_title'];
}
bbp_get_template_part( 'content', 'statistics' );
echo $args['after_widget'];
}
/**
* Update the statistics widget options
*
* @since 2.3.0 bbPress (r4509)
*
* @param array $new_instance The new instance options
* @param array $old_instance The old instance options
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
/**
* Output the statistics widget options form
*
* @since 2.3.0 bbPress (r4509)
*
* @param $instance
*
* @return string|void
*/
public function form( $instance ) {
// Get widget settings
$settings = $this->parse_settings( $instance ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
<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'] ); ?>"/>
</label>
</p>
<?php
}
/**
* Merge the widget settings into defaults array.
*
* @since 2.3.0 bbPress (r4802)
*
* @param $instance Instance
*/
public function parse_settings( $instance = array() ) {
return bbp_parse_args( $instance, array(
'title' => esc_html__( 'Forum Statistics', 'bbpress' )
), 'stats_widget_settings' );
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
Methods Methods
- __construct — bbPress Statistics Widget
- form — Output the statistics widget options form
- parse_settings — Merge the widget settings into defaults array.
- register_widget — Register the widget
- update — Update the statistics widget options
- widget — Displays the output, the statistics