Make WordPress Core

Changeset 40673


Ignore:
Timestamp:
05/15/2017 10:35:41 PM (8 years ago)
Author:
westonruter
Message:

Widgets: Ensure return value of widget_text filter is not dropped but passed into widget_text_content filter for rendering.

Amends [40631].
Props vijustin, swissspidy, westonruter.
See #35243.
Fixes #40772.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-text.php

    r40631 r40673  
    6868        $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
    6969
    70         $widget_text = ! empty( $instance['text'] ) ? $instance['text'] : '';
     70        $text = ! empty( $instance['text'] ) ? $instance['text'] : '';
    7171
    7272        /**
     
    7676         * @since 4.4.0 Added the `$this` parameter.
    7777         *
    78          * @param string         $widget_text The widget content.
    79          * @param array          $instance    Array of settings for the current widget.
    80          * @param WP_Widget_Text $this        Current Text widget instance.
     78         * @param string         $text    The widget content.
     79         * @param array          $instance Array of settings for the current widget.
     80         * @param WP_Widget_Text $this     Current Text widget instance.
    8181         */
    82         $text = apply_filters( 'widget_text', $widget_text, $instance, $this );
     82        $text = apply_filters( 'widget_text', $text, $instance, $this );
    8383
    8484        if ( isset( $instance['filter'] ) ) {
     
    9292                 * @since 4.8.0
    9393                 *
    94                  * @param string         $widget_text The widget content.
    95                  * @param array          $instance    Array of settings for the current widget.
    96                  * @param WP_Widget_Text $this        Current Text widget instance.
     94                 * @param string         $text    The widget content.
     95                 * @param array          $instance Array of settings for the current widget.
     96                 * @param WP_Widget_Text $this     Current Text widget instance.
    9797                 */
    98                 $text = apply_filters( 'widget_text_content', $widget_text, $instance, $this );
     98                $text = apply_filters( 'widget_text_content', $text, $instance, $this );
    9999
    100100            } elseif ( $instance['filter'] ) {
  • trunk/tests/phpunit/tests/widgets/text-widget.php

    r40640 r40673  
    7575        );
    7676
    77         add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 10, 3 );
    78         add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 10, 3 );
     77        add_filter( 'widget_text_content', array( $this, 'filter_widget_text_content' ), 5, 3 );
     78        add_filter( 'widget_text', array( $this, 'filter_widget_text' ), 5, 3 );
    7979
    8080        // Test with filter=false.
     
    8686        $this->assertEmpty( $this->widget_text_content_args );
    8787        $this->assertNotEmpty( $this->widget_text_args );
     88        $this->assertContains( '[filter:widget_text]', $output );
     89        $this->assertNotContains( '[filter:widget_text_content]', $output );
    8890
    8991        // Test with filter=true.
     
    99101        $this->assertEquals( $widget, $this->widget_text_args[2] );
    100102        $this->assertEmpty( $this->widget_text_content_args );
     103        $this->assertContains( '[filter:widget_text]', $output );
     104        $this->assertNotContains( '[filter:widget_text_content]', $output );
    101105
    102106        // Test with filter=content, the upgraded widget.
     
    112116        $this->assertEquals( $widget, $this->widget_text_args[2] );
    113117        $this->assertCount( 3, $this->widget_text_content_args );
    114         $this->assertEquals( wpautop( $instance['text'] ), $this->widget_text_content_args[0] );
     118        $this->assertEquals( $instance['text'] . '[filter:widget_text]', $this->widget_text_content_args[0] );
    115119        $this->assertEquals( $instance, $this->widget_text_content_args[1] );
    116120        $this->assertEquals( $widget, $this->widget_text_content_args[2] );
     121        $this->assertContains( wpautop( $instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output );
    117122    }
    118123
     
    128133        $this->widget_text_args = func_get_args();
    129134
     135        $widget_text .= '[filter:widget_text]';
    130136        return $widget_text;
    131137    }
     
    142148        $this->widget_text_content_args = func_get_args();
    143149
     150        $widget_text .= '[filter:widget_text_content]';
    144151        return $widget_text;
    145152    }
Note: See TracChangeset for help on using the changeset viewer.