diff --git src/wp-includes/widgets/class-wp-widget-text.php src/wp-includes/widgets/class-wp-widget-text.php
index 434a123f90..b3ffd90b18 100644
|
|
class WP_Widget_Text extends WP_Widget { |
67 | 67 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
68 | 68 | $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
69 | 69 | |
70 | | $widget_text = ! empty( $instance['text'] ) ? $instance['text'] : ''; |
| 70 | $text = ! empty( $instance['text'] ) ? $instance['text'] : ''; |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Filters the content of the Text widget. |
… |
… |
class WP_Widget_Text extends WP_Widget { |
75 | 75 | * @since 2.3.0 |
76 | 76 | * @since 4.4.0 Added the `$this` parameter. |
77 | 77 | * |
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. |
81 | 81 | */ |
82 | | $text = apply_filters( 'widget_text', $widget_text, $instance, $this ); |
| 82 | $text = apply_filters( 'widget_text', $text, $instance, $this ); |
83 | 83 | |
84 | 84 | if ( isset( $instance['filter'] ) ) { |
85 | 85 | if ( 'content' === $instance['filter'] ) { |
… |
… |
class WP_Widget_Text extends WP_Widget { |
91 | 91 | * |
92 | 92 | * @since 4.8.0 |
93 | 93 | * |
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. |
97 | 97 | */ |
98 | | $text = apply_filters( 'widget_text_content', $widget_text, $instance, $this ); |
| 98 | $text = apply_filters( 'widget_text_content', $text, $instance, $this ); |
99 | 99 | |
100 | 100 | } elseif ( $instance['filter'] ) { |
101 | 101 | $text = wpautop( $text ); // Back-compat for instances prior to 4.8. |
diff --git tests/phpunit/tests/widgets/text-widget.php tests/phpunit/tests/widgets/text-widget.php
index 81419051b6..a28e6a668a 100644
|
|
class Test_WP_Widget_Text extends WP_UnitTestCase { |
74 | 74 | 'filter' => false, |
75 | 75 | ); |
76 | 76 | |
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 ); |
79 | 79 | |
80 | 80 | // Test with filter=false. |
81 | 81 | ob_start(); |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
85 | 85 | $this->assertNotContains( '<br />', $output ); |
86 | 86 | $this->assertEmpty( $this->widget_text_content_args ); |
87 | 87 | $this->assertNotEmpty( $this->widget_text_args ); |
| 88 | $this->assertContains( '[filter:widget_text]', $output ); |
| 89 | $this->assertNotContains( '[filter:widget_text_content]', $output ); |
88 | 90 | |
89 | 91 | // Test with filter=true. |
90 | 92 | $instance['filter'] = true; |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
98 | 100 | $this->assertEquals( $instance, $this->widget_text_args[1] ); |
99 | 101 | $this->assertEquals( $widget, $this->widget_text_args[2] ); |
100 | 102 | $this->assertEmpty( $this->widget_text_content_args ); |
| 103 | $this->assertContains( '[filter:widget_text]', $output ); |
| 104 | $this->assertNotContains( '[filter:widget_text_content]', $output ); |
101 | 105 | |
102 | 106 | // Test with filter=content, the upgraded widget. |
103 | 107 | $instance['filter'] = 'content'; |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
111 | 115 | $this->assertEquals( $instance, $this->widget_text_args[1] ); |
112 | 116 | $this->assertEquals( $widget, $this->widget_text_args[2] ); |
113 | 117 | $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] ); |
115 | 119 | $this->assertEquals( $instance, $this->widget_text_content_args[1] ); |
116 | 120 | $this->assertEquals( $widget, $this->widget_text_content_args[2] ); |
| 121 | $this->assertContains( wpautop( $instance['text'] . '[filter:widget_text][filter:widget_text_content]' ), $output ); |
117 | 122 | } |
118 | 123 | |
119 | 124 | /** |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
127 | 132 | function filter_widget_text( $widget_text, $instance, $widget ) { |
128 | 133 | $this->widget_text_args = func_get_args(); |
129 | 134 | |
| 135 | $widget_text .= '[filter:widget_text]'; |
130 | 136 | return $widget_text; |
131 | 137 | } |
132 | 138 | |
… |
… |
class Test_WP_Widget_Text extends WP_UnitTestCase { |
141 | 147 | function filter_widget_text_content( $widget_text, $instance, $widget ) { |
142 | 148 | $this->widget_text_content_args = func_get_args(); |
143 | 149 | |
| 150 | $widget_text .= '[filter:widget_text_content]'; |
144 | 151 | return $widget_text; |
145 | 152 | } |
146 | 153 | |