]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets/class-wp-widget-search.php
WordPress 4.4
[autoinstalls/wordpress.git] / wp-includes / widgets / class-wp-widget-search.php
1 <?php
2 /**
3  * Widget API: WP_Widget_Search class
4  *
5  * @package WordPress
6  * @subpackage Widgets
7  * @since 4.4.0
8  */
9
10 /**
11  * Core class used to implement a Search widget.
12  *
13  * @since 2.8.0
14  *
15  * @see WP_Widget
16  */
17 class WP_Widget_Search extends WP_Widget {
18
19         /**
20          * Sets up a new Search widget instance.
21          *
22          * @since 2.8.0
23          * @access public
24          */
25         public function __construct() {
26                 $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );
27                 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
28         }
29
30         /**
31          * Outputs the content for the current Search widget instance.
32          *
33          * @since 2.8.0
34          * @access public
35          *
36          * @param array $args     Display arguments including 'before_title', 'after_title',
37          *                        'before_widget', and 'after_widget'.
38          * @param array $instance Settings for the current Search widget instance.
39          */
40         public function widget( $args, $instance ) {
41                 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
42                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
43
44                 echo $args['before_widget'];
45                 if ( $title ) {
46                         echo $args['before_title'] . $title . $args['after_title'];
47                 }
48
49                 // Use current theme search form if it exists
50                 get_search_form();
51
52                 echo $args['after_widget'];
53         }
54
55         /**
56          * Outputs the settings form for the Search widget.
57          *
58          * @since 2.8.0
59          * @access public
60          *
61          * @param array $instance Current settings.
62          */
63         public function form( $instance ) {
64                 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
65                 $title = $instance['title'];
66                 ?>
67                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <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($title); ?>" /></label></p>
68                 <?php
69         }
70
71         /**
72          * Handles updating settings for the current Search widget instance.
73          *
74          * @since 2.8.0
75          * @access public
76          *
77          * @param array $new_instance New settings for this instance as input by the user via
78          *                            WP_Widget::form().
79          * @param array $old_instance Old settings for this instance.
80          * @return array Updated settings.
81          */
82         public function update( $new_instance, $old_instance ) {
83                 $instance = $old_instance;
84                 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
85                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
86                 return $instance;
87         }
88
89 }