diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
index c3be679516..4637a017b1 100644
|
|
|
function the_widget( $widget, $instance = array(), $args = array() ) { |
| 1125 | 1125 | |
| 1126 | 1126 | $instance = wp_parse_args( $instance ); |
| 1127 | 1127 | |
| | 1128 | /** |
| | 1129 | * Filter the settings for a particular widget instance. |
| | 1130 | * |
| | 1131 | * Returning false will effectively short-circuit display of the widget. |
| | 1132 | * |
| | 1133 | * @since 5.3.0 |
| | 1134 | * |
| | 1135 | * @param array $instance The current widget instance's settings. |
| | 1136 | * @param WP_Widget $widget_obj The current widget instance. |
| | 1137 | * @param array $args An array of default widget arguments. |
| | 1138 | **/ |
| | 1139 | $instance = apply_filters( 'widget_display_callback', $instance, $widget_obj, $args ); |
| | 1140 | |
| | 1141 | if ( false === $instance ) { |
| | 1142 | return; |
| | 1143 | } |
| | 1144 | |
| 1128 | 1145 | /** |
| 1129 | 1146 | * Fires before rendering the requested widget. |
| 1130 | 1147 | * |
diff --git tests/phpunit/tests/widgets.php tests/phpunit/tests/widgets.php
index 4d404100f6..cc95ac572c 100644
|
|
|
class Tests_Widgets extends WP_UnitTestCase { |
| 1160 | 1160 | ); |
| 1161 | 1161 | $this->assertEquals( $expected_sidebars, $new_next_theme_sidebars ); |
| 1162 | 1162 | } |
| | 1163 | |
| | 1164 | /** |
| | 1165 | * @ticket 34226 |
| | 1166 | */ |
| | 1167 | public function test_the_widget_should_shortcircuit_with_widget_display_callback() { |
| | 1168 | |
| | 1169 | add_filter( 'widget_display_callback', '__return_false' ); |
| | 1170 | |
| | 1171 | register_widget( 'WP_Widget_Text' ); |
| | 1172 | |
| | 1173 | ob_start(); |
| | 1174 | the_widget( 'WP_Widget_Text' ); |
| | 1175 | $widget_content = ob_get_clean(); |
| | 1176 | unregister_widget( 'WP_Widget_Text' ); |
| | 1177 | |
| | 1178 | $this->assertSame( '', $widget_content ); |
| | 1179 | } |
| | 1180 | |
| 1163 | 1181 | } |