From 38db73cff806dfa86d7a2e96562b79ae9e586ab1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2017 23:54:42 +0000 Subject: [PATCH] Widgets: Add widget dedicated for HTML Code, taking over this role of the Text widget. Props westonruter, timmydcrawford. See #40951, #35243. Fixes #40907. Built from https://develop.svn.wordpress.org/trunk@40893 git-svn-id: http://core.svn.wordpress.org/trunk@40743 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 2 + wp-includes/default-widgets.php | 3 + wp-includes/version.php | 2 +- wp-includes/widgets.php | 2 + .../widgets/class-wp-widget-html-code.php | 139 ++++++++++++++++++ wp-includes/widgets/class-wp-widget-text.php | 2 +- 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 wp-includes/widgets/class-wp-widget-html-code.php diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 8f0237028d..6f64ffab5d 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -170,6 +170,8 @@ add_filter( 'widget_text_content', 'wptexturize' ); add_filter( 'widget_text_content', 'convert_smilies', 20 ); add_filter( 'widget_text_content', 'wpautop' ); +add_filter( 'widget_html_code_content', 'balanceTags' ); + add_filter( 'date_i18n', 'wp_maybe_decline_date' ); // RSS filters diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index 87ad9dbfb3..32a908ac11 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -60,3 +60,6 @@ require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-tag-cloud.php' ); /** WP_Nav_Menu_Widget class */ require_once( ABSPATH . WPINC . '/widgets/class-wp-nav-menu-widget.php' ); + +/** WP_Widget_HTML_Code class */ +require_once( ABSPATH . WPINC . '/widgets/class-wp-widget-html-code.php' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index c22179c634..4df4441d99 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-40892'; +$wp_version = '4.9-alpha-40893'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index caa575b149..b44048d641 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -1474,6 +1474,8 @@ function wp_widgets_init() { register_widget( 'WP_Nav_Menu_Widget' ); + register_widget( 'WP_Widget_HTML_Code' ); + /** * Fires after all default WordPress widgets have been registered. * diff --git a/wp-includes/widgets/class-wp-widget-html-code.php b/wp-includes/widgets/class-wp-widget-html-code.php new file mode 100644 index 0000000000..d16900183f --- /dev/null +++ b/wp-includes/widgets/class-wp-widget-html-code.php @@ -0,0 +1,139 @@ + '', + 'content' => '', + ); + + /** + * Sets up a new HTML Code widget instance. + * + * @since 4.8.1 + */ + public function __construct() { + $widget_ops = array( + 'classname' => 'widget_html_code', + 'description' => __( 'Arbitrary HTML code.' ), + 'customize_selective_refresh' => true, + ); + $control_ops = array(); + parent::__construct( 'html_code', __( 'HTML Code' ), $widget_ops, $control_ops ); + } + + /** + * Outputs the content for the current HTML Code widget instance. + * + * @since 4.8.1 + * + * @param array $args Display arguments including 'before_title', 'after_title', + * 'before_widget', and 'after_widget'. + * @param array $instance Settings for the current HTML Code widget instance. + */ + public function widget( $args, $instance ) { + + $instance = array_merge( $this->default_instance, $instance ); + + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); + + $content = $instance['content']; + + /** + * Filters the content of the HTML Code widget. + * + * @since 4.8.1 + * + * @param string $content The widget content. + * @param array $instance Array of settings for the current widget. + * @param WP_Widget_HTML_Code $this Current HTML Code widget instance. + */ + $content = apply_filters( 'widget_html_code_content', $content, $instance, $this ); + + echo $args['before_widget']; + if ( ! empty( $title ) ) { + echo $args['before_title'] . $title . $args['after_title']; + } + echo $content; + echo $args['after_widget']; + } + + /** + * Handles updating settings for the current HTML Code widget instance. + * + * @since 4.8.1 + * + * @param array $new_instance New settings for this instance as input by the user via + * WP_Widget::form(). + * @param array $old_instance Old settings for this instance. + * @return array Settings to save or bool false to cancel saving. + */ + public function update( $new_instance, $old_instance ) { + $instance = array_merge( $this->default_instance, $old_instance ); + $instance['title'] = sanitize_text_field( $new_instance['title'] ); + if ( current_user_can( 'unfiltered_html' ) ) { + $instance['content'] = $new_instance['content']; + } else { + $instance['content'] = wp_kses_post( $new_instance['content'] ); + } + return $instance; + } + + /** + * Outputs the HTML Code widget settings form. + * + * @since 4.8.1 + * + * @param array $instance Current instance. + * @returns void + */ + public function form( $instance ) { + $instance = wp_parse_args( (array) $instance, $this->default_instance ); + ?> +

+ + +

+ +

+ + +

+ + + + +

+ + , ', $disallowed_html ); ?> +

+ + + 'widget_text', - 'description' => __( 'Arbitrary text or HTML.' ), + 'description' => __( 'Arbitrary text.' ), 'customize_selective_refresh' => true, ); $control_ops = array(