#19450 closed defect (bug) (fixed)
the_widget won't replace the widget class if not using the default sidebar arguments
Reported by: | Felipelavinz | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | minor | Version: | 3.2.1 |
Component: | Widgets | Keywords: | has-patch |
Focuses: | Cc: |
Description
When using the_widget(), the $before_widget argument only receives the widget class if using the default sidebar arguments...
on lines 1129 - 1130 of wp-includes/widgets.php (wp 3.3 rc 1)
$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>' ); $args = wp_parse_args($args, $default_args);
could be replaced by:
$default_args = array( 'before_widget' => '<div class="widget %s">', 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); $args = wp_parse_pargs($args, $default_args); $args['before_widget'] = sprintf($args['before_widget'], $widget_obj->widget_options['classname']);
Attachments (2)
Change History (8)
#1
@
12 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Awaiting Review to Future Release
- Version set to 3.2.1
#3
@
10 years ago
Added 19450.2.diff as a refresh of 19450.diff, namely to add a unit test.
As stated before, most of the change is whitespace. The patch essentially just moves the execution of sprintf()
for the 'before_widget' value until after the call to wp_parse_args()
to allow any customized 'before_widget' string to still get the benefit of the auto-assignment of the default classname by including '%s' in the string.
Note: See
TracTickets for help on using
tickets.
Added 19450.diff.
As originally reported, it is true that when using
the_widget()
, if you override thebefore_widget
arg for the widget, there is no way to gain the benefit of auto-assignment of the default classname. The defaultbefore_widget
value is defined as<div class="widget %s">
. However, the %s gets replaced prior to use in the defaults arg array (and thus prior to being passed throughwp_parse_args()
to determine the final arg array).The patch, as originally proposed by @Felipelavinz, simply delays the
sprintf()
substitution until after thewp_parse_args()
completes, allowing the following example to work properly:There should be no compatibility issues or any other drawbacks to its implementation.