Ticket #4910 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Widgets might get "Array" as CSS class instead of classname

Reported by: f00f Assigned to: anonymous
Priority: high Milestone: 2.3
Component: General Version: 2.3
Severity: minor Keywords: widgets css class has-patch dev-reviewed
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

4910.003.diff (0.9 kB) - added by markjaquith on 09/11/07 21:49:52.

Change History

09/06/07 23:27:16 changed by markjaquith

  • status changed from new to closed.
  • resolution set to fixed.

(In [6054]) Properly construct widget classname if second param is an array. Props f00f. fixes #4910

09/11/07 19:40:41 changed by mattyrob

  • status changed from closed to reopened.
  • resolution deleted.

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'];

09/11/07 21:49:27 changed by markjaquith

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).

09/11/07 21:49:52 changed by markjaquith

  • attachment 4910.003.diff added.

09/12/07 01:36:52 changed by andy

Sweet.

09/12/07 06:50:42 changed by westi

  • keywords changed from widgets css class has-patch to widgets css class has-patch dev-reviewed.

that new patch looks good and should solve this issue.

(in reply to: ↑ description ) 09/12/07 08:15:42 changed by mattyrob

New patch works for me.

09/12/07 20:48:21 changed by markjaquith

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [6098]) Set widget classname when passed string, object/method, object-reference/method. fixes #4910