Skip to content
Permalink
Browse files

Widgets: Allow for short-circuiting widget output in `the_widget()` u…

…sing the `widget_display_callback` filter, for consistency with output via a registered sidebar.

Props MarcGuay, donmhico.
Fixes #34226.

git-svn-id: https://develop.svn.wordpress.org/trunk@45798 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Aug 14, 2019
1 parent 1177e12 commit a2a28e46083fd8f96aab9f70a156967b4df7587c
Showing with 23 additions and 0 deletions.
  1. +7 −0 src/wp-includes/widgets.php
  2. +16 −0 tests/phpunit/tests/widgets.php
@@ -1125,6 +1125,13 @@ function the_widget( $widget, $instance = array(), $args = array() ) {
$instance = wp_parse_args( $instance );
/** This filter is documented in wp-includes/class-wp-widget.php */
$instance = apply_filters( 'widget_display_callback', $instance, $widget_obj, $args );
if ( false === $instance ) {
return;
}
/**
* Fires before rendering the requested widget.
*
@@ -712,6 +712,22 @@ function test_the_widget_with_unregistered_widget() {
the_widget( 'Widget_Class' );
}
/**
* @ticket 34226
*/
public function test_the_widget_should_short_circuit_with_widget_display_callback() {
add_filter( 'widget_display_callback', '__return_false' );
register_widget( 'WP_Widget_Text' );
ob_start();
the_widget( 'WP_Widget_Text' );
$widget_content = ob_get_clean();
unregister_widget( 'WP_Widget_Text' );
$this->assertEmpty( $widget_content );
}
/**
* Register nav menu sidebars.
*

0 comments on commit a2a28e4

Please sign in to comment.
You can’t perform that action at this time.