]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets/class-wp-widget-search.php
WordPress 4.7
[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(
27                         'classname' => 'widget_search',
28                         'description' => __( 'A search form for your site.' ),
29                         'customize_selective_refresh' => true,
30                 );
31                 parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
32         }
33
34         /**
35          * Outputs the content for the current Search widget instance.
36          *
37          * @since 2.8.0
38          * @access public
39          *
40          * @param array $args     Display arguments including 'before_title', 'after_title',
41          *                        'before_widget', and 'after_widget'.
42          * @param array $instance Settings for the current Search widget instance.
43          */
44         public function widget( $args, $instance ) {
45                 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
46                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
47
48                 echo $args['before_widget'];
49                 if ( $title ) {
50                         echo $args['before_title'] . $title . $args['after_title'];
51                 }
52
53                 // Use current theme search form if it exists
54                 get_search_form();
55
56                 echo $args['after_widget'];
57         }
58
59         /**
60          * Outputs the settings form for the Search widget.
61          *
62          * @since 2.8.0
63          * @access public
64          *
65          * @param array $instance Current settings.
66          */
67         public function form( $instance ) {
68                 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
69                 $title = $instance['title'];
70                 ?>
71                 <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>
72                 <?php
73         }
74
75         /**
76          * Handles updating settings for the current Search widget instance.
77          *
78          * @since 2.8.0
79          * @access public
80          *
81          * @param array $new_instance New settings for this instance as input by the user via
82          *                            WP_Widget::form().
83          * @param array $old_instance Old settings for this instance.
84          * @return array Updated settings.
85          */
86         public function update( $new_instance, $old_instance ) {
87                 $instance = $old_instance;
88                 $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
89                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
90                 return $instance;
91         }
92
93 }