Opened 17 years ago
Closed 17 years ago
#4910 closed defect (bug) (fixed)
Widgets might get "Array" as CSS class instead of classname
Reported by: | f00f | Owned by: | |
---|---|---|---|
Milestone: | 2.3 | Priority: | high |
Severity: | minor | Version: | 2.3 |
Component: | General | Keywords: | widgets css class has-patch dev-reviewed |
Focuses: | Cc: |
Description
When register_sidebar_widget is called with two parameters only and the second one is an array, like
register_sidebar_widget(__('WdgName'), array('WdgClass', 'Method'));
then the CSS class attribute of the widget will contain 'Array' where it should contain the class_name.
Fix: implode classname if it's an array.
File: widgets.php
Line: Replace line 213 with those two lines:
$classname_ = is_array($wp_registered_widgets[$id]['classname']) ? implode('_', $wp_registered_widgets[$id]['classname']) : $wp_registered_widgets[$id]['classname']; $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
Btw: I do know (now) that there is a third parameter to register_sidebar_widget(), but we'd better be save than sorry.
The fix should be absolutely save because only local variable is affected.
Sorry for not providing a diff, how do I create one? (Win32)
Easy fix, please include in 2.3 kthxbye ;)
Attachments (1)
Change History (8)
#2
@
17 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
This changeset has broken my widget called from within a class as follows:
register_sidebar_widget('Subscribe2Widget', array(&$this, 'widget_subscribe2widget'));
With the following error:
Catchable fatal error: Object of class s2class could not be converted to string in /Users/Matthew/Sites/trunk/wp-includes/widgets.php on line 213
A fix appears to be as follows:
$classname_ = ( is_array($wp_registered_widgets[$id]['classname']) ) ? $wp_registered_widgets[$id]['classname'][1] : $wp_registered_widgets[$id]['classname'];
#3
@
17 years ago
I don't like that, because it only uses the method name, which could be quite generic.
How about this version? If passed a string, it uses it. If passed an array with a class name and method, it uses them (with _ in the middle). If passed an array with an object reference and method, it extracts the object's class name and uses that plus the method (with _ in the middle).
#5
@
17 years ago
- Keywords dev-reviewed added
that new patch looks good and should solve this issue.
#6
in reply to:
↑ description
@
17 years ago
New patch works for me.
(In [6054]) Properly construct widget classname if second param is an array. Props f00f. fixes #4910