]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/widgets/class-wp-widget-text.php
WordPress 4.4
[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('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.'));
27                 $control_ops = array('width' => 400, 'height' => 350);
28                 parent::__construct('text', __('Text'), $widget_ops, $control_ops);
29         }
30
31         /**
32          * Outputs the content for the current Text 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 Text widget instance.
40          */
41         public function widget( $args, $instance ) {
42
43                 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
44                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
45
46                 $widget_text = ! empty( $instance['text'] ) ? $instance['text'] : '';
47
48                 /**
49                  * Filter the content of the Text widget.
50                  *
51                  * @since 2.3.0
52                  * @since 4.4.0 Added the `$this` parameter.
53                  *
54                  * @param string         $widget_text The widget content.
55                  * @param array          $instance    Array of settings for the current widget.
56                  * @param WP_Widget_Text $this        Current Text widget instance.
57                  */
58                 $text = apply_filters( 'widget_text', $widget_text, $instance, $this );
59
60                 echo $args['before_widget'];
61                 if ( ! empty( $title ) ) {
62                         echo $args['before_title'] . $title . $args['after_title'];
63                 } ?>
64                         <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
65                 <?php
66                 echo $args['after_widget'];
67         }
68
69         /**
70          * Handles updating settings for the current Text widget instance.
71          *
72          * @since 2.8.0
73          * @access public
74          *
75          * @param array $new_instance New settings for this instance as input by the user via
76          *                            WP_Widget::form().
77          * @param array $old_instance Old settings for this instance.
78          * @return array Settings to save or bool false to cancel saving.
79          */
80         public function update( $new_instance, $old_instance ) {
81                 $instance = $old_instance;
82                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
83                 if ( current_user_can('unfiltered_html') )
84                         $instance['text'] =  $new_instance['text'];
85                 else
86                         $instance['text'] = wp_kses_post( stripslashes( $new_instance['text'] ) );
87                 $instance['filter'] = ! empty( $new_instance['filter'] );
88                 return $instance;
89         }
90
91         /**
92          * Outputs the Text widget settings form.
93          *
94          * @since 2.8.0
95          * @access public
96          *
97          * @param array $instance Current settings.
98          */
99         public function form( $instance ) {
100                 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
101                 $filter = isset( $instance['filter'] ) ? $instance['filter'] : 0;
102                 $title = sanitize_text_field( $instance['title'] );
103                 ?>
104                 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
105                 <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>
106
107                 <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
108                 <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>
109
110                 <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>
111                 <?php
112         }
113 }