Make WordPress Core

Changeset 41087


Ignore:
Timestamp:
07/18/2017 10:18:12 PM (9 years ago)
Author:
westonruter
Message:

Widgets: Replace adding balanceTags on widget_custom_html_content filter in favor of just applying widget_text filters in Custom HTML widget.

Ensures that users who copy HTML from the Text widget in legacy mode over to the Custom HTML widget will continue to get all of the same filters applied, including tag balancing and shortcodes, if a plugin added support. Plugins still have the widget_text_content and widget_custom_html_content filters they can use to target the specific widget types.

Merges [41086] onto 4.8 branch.
Amends [40893].
See #40951.
Fixes #40907 for 4.8.1.

Location:
branches/4.8
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/src/wp-includes/default-filters.php

    r41044 r41087  
    170170add_filter( 'widget_text_content', 'convert_smilies',  20 );
    171171add_filter( 'widget_text_content', 'wpautop'              );
    172 
    173 add_filter( 'widget_custom_html_content', 'balanceTags' );
    174172
    175173add_filter( 'date_i18n', 'wp_maybe_decline_date' );
  • branches/4.8/src/wp-includes/default-widgets.php

    r41044 r41087  
    120120                $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
    121121
    122                 $content = $instance['content'];
     122                /** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
     123                $content = apply_filters( 'widget_text', $instance['content'], $instance, $this );
    123124
    124125                /**
  • branches/4.8/src/wp-includes/widgets/class-wp-widget-text.php

    r41071 r41087  
    214214                 * @since 2.3.0
    215215                 * @since 4.4.0 Added the `$this` parameter.
     216                 * @since 4.8.1 The `$this` param may now be a `WP_Widget_Custom_HTML` object in addition to a `WP_Widget_Text` object.
    216217                 *
    217                  * @param string         $text     The widget content.
    218                  * @param array          $instance Array of settings for the current widget.
    219                  * @param WP_Widget_Text $this     Current Text widget instance.
     218                 * @param string                               $text     The widget content.
     219                 * @param array                                $instance Array of settings for the current widget.
     220                 * @param WP_Widget_Text|WP_Widget_Custom_HTML $this     Current Text widget instance.
    220221                 */
    221222                $text = apply_filters( 'widget_text', $text, $instance, $this );
  • branches/4.8/tests/phpunit/tests/widgets/custom-html-widget.php

    r41044 r41087  
    2020         */
    2121        protected $widget_custom_html_content_args;
     22
     23        /**
     24         * Args passed to the widget_text filter.
     25         *
     26         * @var array
     27         */
     28        protected $widget_text_args;
    2229
    2330        /**
     
    5360                );
    5461
    55                 $this->assertEquals( 10, has_filter( 'widget_custom_html_content', 'balanceTags' ) );
    56 
    5762                update_option( 'use_balanceTags', 0 );
    5863                add_filter( 'widget_custom_html_content', array( $this, 'filter_widget_custom_html_content' ), 5, 3 );
     64                add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10, 3 );
    5965                ob_start();
    6066                $this->widget_custom_html_content_args = null;
     67                $this->widget_text_args = null;
    6168                $widget->widget( $args, $instance );
    6269                $output = ob_get_clean();
    6370                $this->assertNotEmpty( $this->widget_custom_html_content_args );
    64                 $this->assertContains( '[filter:widget_custom_html_content]', $output );
     71                $this->assertNotEmpty( $this->widget_text_args );
     72                $this->assertContains( '[filter:widget_text][filter:widget_custom_html_content]', $output );
    6573                $this->assertNotContains( '<p>', $output );
    6674                $this->assertNotContains( '<br>', $output );
    6775                $this->assertNotContains( '</u>', $output );
     76                $this->assertEquals( $instance, $this->widget_text_args[1] );
    6877                $this->assertEquals( $instance, $this->widget_custom_html_content_args[1] );
     78                $this->assertSame( $widget, $this->widget_text_args[2] );
    6979                $this->assertSame( $widget, $this->widget_custom_html_content_args[2] );
    7080                remove_filter( 'widget_custom_html_content', array( $this, 'filter_widget_custom_html_content' ), 5, 3 );
     81                remove_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10 );
    7182
    7283                update_option( 'use_balanceTags', 1 );
     
    7889
    7990        /**
    80          * Filters the content of the Custom HTML widget.
     91         * Filters the content of the Custom HTML widget using the legacy widget_text filter.
     92         *
     93         * @param string                $text     The widget content.
     94         * @param array                 $instance Array of settings for the current widget.
     95         * @param WP_Widget_Custom_HTML $widget   Current widget instance.
     96         * @return string Widget content.
     97         */
     98        function filter_widget_text( $text, $instance, $widget ) {
     99                $this->widget_text_args = array( $text, $instance, $widget );
     100                $text .= '[filter:widget_text]';
     101                return $text;
     102        }
     103
     104        /**
     105         * Filters the content of the Custom HTML widget using the dedicated widget_custom_html_content filter.
    81106         *
    82107         * @param string                $widget_content The widget content.
     
    86111         */
    87112        function filter_widget_custom_html_content( $widget_content, $instance, $widget ) {
    88                 $this->widget_custom_html_content_args = func_get_args();
    89 
     113                $this->widget_custom_html_content_args = array( $widget_content, $instance, $widget );
    90114                $widget_content .= '[filter:widget_custom_html_content]';
    91115                return $widget_content;
Note: See TracChangeset for help on using the changeset viewer.