Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

class-wp-widget-search.php 2.6 KiB

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