WP_Widget_Search

Core class used to implement a Search widget.

Defined (1)

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

/wp-includes/widgets/class-wp-widget-search.php  
  1. class WP_Widget_Search extends WP_Widget { 
  2.  
  3. /** 
  4. * Sets up a new Search widget instance. 
  5. * @since 2.8.0 
  6. * @access public 
  7. */ 
  8. public function __construct() { 
  9. $widget_ops = array( 
  10. 'classname' => 'widget_search',  
  11. 'description' => __( 'A search form for your site.' ),  
  12. 'customize_selective_refresh' => true,  
  13. ); 
  14. parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); 
  15.  
  16. /** 
  17. * Outputs the content for the current Search widget instance. 
  18. * @since 2.8.0 
  19. * @access public 
  20. * @param array $args Display arguments including 'before_title', 'after_title',  
  21. * 'before_widget', and 'after_widget'. 
  22. * @param array $instance Settings for the current Search widget instance. 
  23. */ 
  24. public function widget( $args, $instance ) { 
  25. /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ 
  26. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 
  27.  
  28. echo $args['before_widget']; 
  29. if ( $title ) { 
  30. echo $args['before_title'] . $title . $args['after_title']; 
  31.  
  32. // Use current theme search form if it exists 
  33. get_search_form(); 
  34.  
  35. echo $args['after_widget']; 
  36.  
  37. /** 
  38. * Outputs the settings form for the Search widget. 
  39. * @since 2.8.0 
  40. * @access public 
  41. * @param array $instance Current settings. 
  42. */ 
  43. public function form( $instance ) { 
  44. $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); 
  45. $title = $instance['title']; 
  46. ?> 
  47. <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> 
  48. <?php 
  49.  
  50. /** 
  51. * Handles updating settings for the current Search widget instance. 
  52. * @since 2.8.0 
  53. * @access public 
  54. * @param array $new_instance New settings for this instance as input by the user via 
  55. * WP_Widget::form(). 
  56. * @param array $old_instance Old settings for this instance. 
  57. * @return array Updated settings. 
  58. */ 
  59. public function update( $new_instance, $old_instance ) { 
  60. $instance = $old_instance; 
  61. $new_instance = wp_parse_args((array) $new_instance, array( 'title' => '')); 
  62. $instance['title'] = sanitize_text_field( $new_instance['title'] ); 
  63. return $instance; 
  64.