Widgets: When using the_widget()
, the $before_widget
argument only receives the widget class if using the default sidebar arguments. Run sprintf
after parsing the args to fix this.
Adds unit test. Props coffee2code. Fixes #19450. git-svn-id: https://develop.svn.wordpress.org/trunk@35106 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c0c0305749
commit
65c8adc252
@ -949,10 +949,15 @@ function the_widget( $widget, $instance = array(), $args = array() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] );
|
||||
$default_args = array( 'before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' );
|
||||
$default_args = array(
|
||||
'before_widget' => '<div class="widget %s">',
|
||||
'after_widget' => "</div>",
|
||||
'before_title' => '<h2 class="widgettitle">',
|
||||
'after_title' => '</h2>',
|
||||
);
|
||||
$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);
|
||||
|
||||
/**
|
||||
|
@ -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' => '<span class="special %s">', 'after_widget' => '</span>' )
|
||||
);
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertRegExp( '/<span class="special widget_text">/', $actual );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user