[wp-hackers] Need WP/PHP guru eyeballs/feedback on my WP_Widget wrapper class

Micky Hulse mickyhulse.lists at gmail.com
Tue Jun 25 17:55:42 UTC 2013


Currently, I have a setup for custom widgets where I create a simple
class for each new widget. For example:


While the above works well, I'm finding that I'm repeating a little
bit of boilerplate code for each widget (even after extending an
abstract class with most of the boilerplate in that).

In an attempt to improve my code, and avoid repeating myself, I
created this class:


Inspired by WPAlchemy, I thought it would be cool to create my custom
widgets like so:


$medium_rectangle_1 = new foo_Widget(
        'id_base' => 'medium_rectangle_1',
        'name' => 'Medium Rectangle 1',
        'description' => 'Standard Advertising Unit',
        'template' => STYLESHEETPATH .


Unfortunately, I keep getting this PHP notice:


Notice: Undefined property: Foo_Widget::$option_name in
/.../wp-includes/widgets.php on line 291 Warning: array_merge():
Argument #2 is not an array in /.../wp-includes/widgets.php on line


... and the widget does not show in the admin (well, there's an empty,
useless, widget box with no label).

Now, I know my code could use some more work (I'm kinda pushing the
limits of my WP/PHP skillz) ... I just wanted to see if anyone here
had any tips as to what I might be doing wrong?


More information about the wp-hackers mailing list