WordPress.org

Make WordPress Core

Ticket #40907: custom-html-widget-shortcode-support.diff

File custom-html-widget-shortcode-support.diff, 1.2 KB (added by westonruter, 2 years ago)
  • src/wp-includes/widgets/class-wp-widget-custom-html.php

    diff --git src/wp-includes/widgets/class-wp-widget-custom-html.php src/wp-includes/widgets/class-wp-widget-custom-html.php
    index 2db50f4d22..349e39fcae 100644
    class WP_Widget_Custom_HTML extends WP_Widget { 
    6363
    6464                $content = $instance['content'];
    6565
     66                // Just-in-time add shortcode handling if a plugin added it for the Text widget.
     67                $add_text_widget_shortcode_handling = (
     68                        false !== has_filter( 'widget_text', 'do_shortcode' )
     69                        &&
     70                        false === has_filter( 'widget_custom_html_content', 'do_shortcode' )
     71                );
     72                if ( $add_text_widget_shortcode_handling ) {
     73                        add_filter( 'widget_custom_html_content', 'do_shortcode', 10, 2 );
     74                }
     75
    6676                /**
    6777                 * Filters the content of the Custom HTML widget.
    6878                 *
    class WP_Widget_Custom_HTML extends WP_Widget { 
    7484                 */
    7585                $content = apply_filters( 'widget_custom_html_content', $content, $instance, $this );
    7686
     87                if ( $add_text_widget_shortcode_handling ) {
     88                        remove_filter( 'widget_custom_html_content', 'do_shortcode' );
     89                }
     90
    7791                echo $args['before_widget'];
    7892                if ( ! empty( $title ) ) {
    7993                        echo $args['before_title'] . $title . $args['after_title'];