diff --git a/src/wp-includes/widget-functions.php b/src/wp-includes/widget-functions.php index 8c9b568935..c9c8268a5e 100644 --- a/src/wp-includes/widget-functions.php +++ b/src/wp-includes/widget-functions.php @@ -949,10 +949,15 @@ function the_widget( $widget, $instance = array(), $args = array() ) { return; } - $before_widget = sprintf('
', $widget_obj->widget_options['classname'] ); - $default_args = array( 'before_widget' => $before_widget, 'after_widget' => "
", 'before_title' => '

', 'after_title' => '

' ); + $default_args = array( + 'before_widget' => '
', + 'after_widget' => "
", + 'before_title' => '

', + 'after_title' => '

', + ); + $args = wp_parse_args( $args, $default_args ); + $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] ); - $args = wp_parse_args($args, $default_args); $instance = wp_parse_args($instance); /** diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index a98942044c..a9c6b62278 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -607,4 +607,19 @@ class Tests_Widgets extends WP_UnitTestCase { $this->assertContains( $contained, $control ); } } + + function test_the_widget_custom_before_title_arg() { + + ob_start(); + the_widget( + 'WP_Widget_Text', + array( 'title' => 'Notes', 'text' => 'Sample text' ), + array( 'before_widget' => '', 'after_widget' => '' ) + ); + $actual = ob_get_clean(); + + $this->assertRegExp( '//', $actual ); + + } + }