BBP_Search_Widget

BbPress Search Widget.

Defined (1)

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

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