Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/16/2012 08:19:21 AM (12 years ago)
Author:
jmdodd
Message:

Introduce dedicated forum search.

  • Search forums, topics, and replies.
  • Add new search functions, including bbp_has_search_results().
  • Provide templates for search results.
  • Fixes #1575.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/common/widgets.php

    r4510r4579 
    306306     * @uses BBP_Views_Widget::get_field_id() To output the field id
    307307     * @uses BBP_Views_Widget::get_field_name() To output the field name
     308     */
     309    public function form( $instance ) {
     310        $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>
     311
     312        <p>
     313            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
     314                <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
     315            </label>
     316        </p>
     317
     318        <?php
     319    }
     320}
     321
     322/**
     323 * bbPress Search Widget
     324 *
     325 * Adds a widget which displays the forum search form
     326 *
     327 * @since bbPress (r4579)
     328 *
     329 * @uses WP_Widget
     330 */
     331class BBP_Search_Widget extends WP_Widget {
     332
     333    /**
     334     * bbPress Search Widget
     335     *
     336     * Registers the search widget
     337     *
     338     * @since bbPress (r4579)
     339     *
     340     * @uses apply_filters() Calls 'bbp_search_widget_options' with the
     341     *                        widget options
     342     */
     343    public function __construct() {
     344        $widget_ops = apply_filters( 'bbp_search_widget_options', array(
     345            'classname'   => 'widget_display_search',
     346            'description' => __( 'The bbPress forum search form.', 'bbpress' )
     347        ) );
     348
     349        parent::__construct( false, __( '(bbPress) Forum Search Form', 'bbpress' ), $widget_ops );
     350    }
     351
     352    /**
     353     * Register the widget
     354     *
     355     * @since bbPress (r4579)
     356     *
     357     * @uses register_widget()
     358     */
     359    public static function register_widget() {
     360        register_widget( 'BBP_Search_Widget' );
     361    }
     362
     363    /**
     364     * Displays the output, the search form
     365     *
     366     * @since bbPress (r4579)
     367     *
     368     * @uses apply_filters() Calls 'bbp_search_widget_title' with the title
     369     * @uses get_template_part() To get the search form
     370     */
     371    public function widget( $args, $instance ) {
     372
     373        // Typical WordPress filter
     374        $title = apply_filters( 'widget_title',            $instance['title'], $instance, $this->id_base );
     375
     376        // bbPress filter
     377        $title = apply_filters( 'bbp_search_widget_title', $instance['title'], $instance, $this->id_base );
     378
     379        echo $args['before_widget'];
     380        echo $args['before_title'] . $title . $args['after_title'];
     381
     382        bbp_get_template_part( 'form', 'search' );
     383
     384        echo $args['after_widget'];
     385    }
     386
     387    /**
     388     * Update the widget options
     389     *
     390     * @since bbPress (r4579)
     391     *
     392     * @param array $new_instance The new instance options
     393     * @param array $old_instance The old instance options
     394     */
     395    public function update( $new_instance, $old_instance ) {
     396        $instance          = $old_instance;
     397        $instance['title'] = strip_tags( $new_instance['title'] );
     398
     399        return $instance;
     400    }
     401
     402    /**
     403     * Output the search widget options form
     404     *
     405     * @since bbPress (r4579)
     406     *
     407     * @param $instance Instance
     408     * @uses BBP_Search_Widget::get_field_id() To output the field id
     409     * @uses BBP_Search_Widget::get_field_name() To output the field name
    308410     */
    309411    public function form( $instance ) {
Note: See TracChangeset for help on using the changeset viewer.