diff --git a/wp-includes/class-wp-customize-widgets.php b/wp-includes/class-wp-customize-widgets.php index 40590f0818..a605b90c49 100644 --- a/wp-includes/class-wp-customize-widgets.php +++ b/wp-includes/class-wp-customize-widgets.php @@ -35,9 +35,23 @@ final class WP_Customize_Widgets { * @var array */ protected $core_widget_id_bases = array( - 'archives', 'calendar', 'categories', 'links', 'meta', - 'nav_menu', 'pages', 'recent-comments', 'recent-posts', - 'rss', 'search', 'tag_cloud', 'text', + 'archives', + 'calendar', + 'categories', + 'custom_html', + 'links', + 'media_audio', + 'media_image', + 'media_video', + 'meta', + 'nav_menu', + 'pages', + 'recent-comments', + 'recent-posts', + 'rss', + 'search', + 'tag_cloud', + 'text', ); /** diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 8f0237028d..ada9c53c3f 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_custom_html_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..2585978907 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -60,3 +60,141 @@ 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' ); + +/** + * Core class used to implement a Custom HTML widget. + * + * Note that this class is only located in this file in the 4.8 branch + * for the sake of automatic updates. In 4.9 and above, it is located at + * `wp-includes/widgets/class-wp-widget-custom-html.php`. + * + * @since 4.8.1 + * + * @see WP_Widget + */ +class WP_Widget_Custom_HTML extends WP_Widget { + + /** + * Default instance. + * + * @since 4.8.1 + * @var array + */ + protected $default_instance = array( + 'title' => '', + 'content' => '', + ); + + /** + * Sets up a new Custom HTML widget instance. + * + * @since 4.8.1 + */ + public function __construct() { + $widget_ops = array( + 'classname' => 'widget_custom_html', + 'description' => __( 'Arbitrary HTML code.' ), + 'customize_selective_refresh' => true, + ); + $control_ops = array( + 'width' => 400, + 'height' => 350, + ); + parent::__construct( 'custom_html', __( 'Custom HTML' ), $widget_ops, $control_ops ); + } + + /** + * Outputs the content for the current Custom HTML 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 Custom HTML 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 Custom HTML widget. + * + * @since 4.8.1 + * + * @param string $content The widget content. + * @param array $instance Array of settings for the current widget. + * @param WP_Widget_Custom_HTML $this Current Custom HTML widget instance. + */ + $content = apply_filters( 'widget_custom_html_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 Custom HTML 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 Custom HTML 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 ); ?>
+