BBP_Views_Widget

BbPress Views Widget.

Defined (1)

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

/includes/common/widgets.php  
  1. class BBP_Views_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * bbPress View Widget 
  5. * Registers the view widget 
  6. * @since bbPress (r3020) 
  7. * @uses apply_filters() Calls 'bbp_views_widget_options' with the 
  8. * widget options 
  9. */ 
  10. public function __construct() { 
  11. $widget_ops = apply_filters( 'bbp_views_widget_options', array( 
  12. 'classname' => 'widget_display_views',  
  13. 'description' => __( 'A list of registered optional topic views.', 'bbpress' ) 
  14. ) ); 
  15.  
  16. parent::__construct( false, __( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops ); 
  17.  
  18. /** 
  19. * Register the widget 
  20. * @since bbPress (r3389) 
  21. * @uses register_widget() 
  22. */ 
  23. public static function register_widget() { 
  24. register_widget( 'BBP_Views_Widget' ); 
  25.  
  26. /** 
  27. * Displays the output, the view list 
  28. * @since bbPress (r3020) 
  29. * @param mixed $args Arguments 
  30. * @param array $instance Instance 
  31. * @uses apply_filters() Calls 'bbp_view_widget_title' with the title 
  32. * @uses bbp_get_views() To get the views 
  33. * @uses bbp_view_url() To output the view url 
  34. * @uses bbp_view_title() To output the view title 
  35. */ 
  36. public function widget( $args = array(), $instance = array() ) { 
  37.  
  38. // Only output widget contents if views exist 
  39. if ( ! bbp_get_views() ) { 
  40. return; 
  41.  
  42. // Get widget settings 
  43. $settings = $this->parse_settings( $instance ); 
  44.  
  45. // Typical WordPress filter 
  46. $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 
  47.  
  48. // bbPress filter 
  49. $settings['title'] = apply_filters( 'bbp_view_widget_title', $settings['title'], $instance, $this->id_base ); 
  50.  
  51. echo $args['before_widget']; 
  52.  
  53. if ( !empty( $settings['title'] ) ) { 
  54. echo $args['before_title'] . $settings['title'] . $args['after_title']; 
  55. } ?> 
  56.  
  57. <ul> 
  58.  
  59. <?php foreach ( array_keys( bbp_get_views() ) as $view ) : ?> 
  60.  
  61. <li><a class="bbp-view-title" href="<?php bbp_view_url( $view ); ?>"><?php bbp_view_title( $view ); ?></a></li> 
  62.  
  63. <?php endforeach; ?> 
  64.  
  65. </ul> 
  66.  
  67. <?php echo $args['after_widget']; 
  68.  
  69. /** 
  70. * Update the view widget options 
  71. * @since bbPress (r3020) 
  72. * @param array $new_instance The new instance options 
  73. * @param array $old_instance The old instance options 
  74. */ 
  75. public function update( $new_instance = array(), $old_instance = array() ) { 
  76. $instance = $old_instance; 
  77. $instance['title'] = strip_tags( $new_instance['title'] ); 
  78.  
  79. return $instance; 
  80.  
  81. /** 
  82. * Output the view widget options form 
  83. * @since bbPress (r3020) 
  84. * @param $instance Instance 
  85. * @uses BBP_Views_Widget::get_field_id() To output the field id 
  86. * @uses BBP_Views_Widget::get_field_name() To output the field name 
  87. */ 
  88. public function form( $instance = array() ) { 
  89.  
  90. // Get widget settings 
  91. $settings = $this->parse_settings( $instance ); ?> 
  92.  
  93. <p> 
  94. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 
  95. <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'] ); ?>" /> 
  96. </label> 
  97. </p> 
  98.  
  99. <?php 
  100.  
  101. /** 
  102. * Merge the widget settings into defaults array. 
  103. * @since bbPress (r4802) 
  104. * @param $instance Instance 
  105. * @uses bbp_parse_args() To merge widget settings into defaults 
  106. */ 
  107. public function parse_settings( $instance = array() ) { 
  108. return bbp_parse_args( $instance, array( 
  109. 'title' => '' 
  110. ), 'view_widget_settings' );