]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets/class-wp-widget-text.php
WordPress 4.6.3-scripts
[autoinstalls/wordpress.git] / wp-includes / widgets / class-wp-widget-text.php
1 <?php
2 /**
3  * Widget API: WP_Widget_Text class
4  *
5  * @package WordPress
6  * @subpackage Widgets
7  * @since 4.4.0
8  */
9
10 /**
11  * Core class used to implement a Text widget.
12  *
13  * @since 2.8.0
14  *
15  * @see WP_Widget
16  */
17 class WP_Widget_Text extends WP_Widget {
18
19         /**
20          * Sets up a new Text widget instance.
21          *
22          * @since 2.8.0
23          * @access public
24          */
25         public function __construct() {
26                 $widget_ops = array(
27                         'classname' => 'widget_text',
28                         'description' => __( 'Arbitrary text or HTML.' ),
29                         'customize_selective_refresh' => true,
30                 );
31                 $control_ops = array( 'width' => 400, 'height' => 350 );
32                 parent::__construct( 'text', __( 'Text' ), $widget_ops, $control_ops );
33         }
34
35         /**
36          * Outputs the content for the current Text widget instance.
37          *
38          * @since 2.8.0
39          * @access public
40          *
41          * @param array $args     Display arguments including 'before_title', 'after_title',
42          *                        'before_widget', and 'after_widget'.
43          * @param array $instance Settings for the current Text widget instance.
44          */
45         public function widget( $args, $instance ) {
46
47                 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
48                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
49
50                 $widget_text = ! empty( $instance['text'] ) ? $instance['text'] : '';
51
52                 /**
53                  * Filters the content of the Text widget.
54                  *
55                  * @since 2.3.0
56                  * @since 4.4.0 Added the `$this` parameter.
57                  *
58                  * @param string         $widget_text The widget content.
59                  * @param array          $instance    Array of settings for the current widget.
60                  * @param WP_Widget_Text $this        Current Text widget instance.
61                  */
62                 $text = apply_filters( 'widget_text', $widget_text, $instance, $this );
63
64                 echo $args['before_widget'];
65                 if ( ! empty( $title ) ) {
66                         echo $args['before_title'] . $title . $args['after_title'];
67                 } ?>
68                         <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
69                 <?php
70                 echo $args['after_widget'];
71         }
72
73         /**
74          * Handles updating settings for the current Text widget instance.
75          *
76          * @since 2.8.0
77          * @access public
78          *
79          * @param array $new_instance New settings for this instance as input by the user via
80          *                            WP_Widget::form().
81          * @param array $old_instance Old settings for this instance.
82          * @return array Settings to save or bool false to cancel saving.
83          */
84         public function update( $new_instance, $old_instance ) {
85                 $instance = $old_instance;
86                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
87                 if ( current_user_can( 'unfiltered_html' ) ) {
88                         $instance['text'] = $new_instance['text'];
89                 } else {
90                         $instance['text'] = wp_kses_post( $new_instance['text'] );
91                 }
92                 $instance['filter'] = ! empty( $new_instance['filter'] );
93                 return $instance;
94         }
95
96         /**
97          * Outputs the Text widget settings form.
98          *
99          * @since 2.8.0
100          * @access public
101          *
102          * @param array $instance Current settings.
103          */
104         public function form( $instance ) {
105                 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
106                 $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;
107                 $title = sanitize_text_field( $instance['title'] );
108                 ?>
109                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
110                 <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); ?>" /></p>
111
112                 <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
113                 <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo esc_textarea( $instance['text'] ); ?></textarea></p>
114
115                 <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox"<?php checked( $filter ); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
116                 <?php
117         }
118 }