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

Micky Hulse mickyhulse.lists at gmail.com
Tue Jun 25 18:20:21 UTC 2013


Thanks for the feedback. I apologize for lack of WordPress version.

I'm running version 3.5.1.

I'll try to create a simple version of my code. I'm pretty sure I get
the same errors when I remove everything but the very basic code.

Thanks for the kick in the pants! :)

Micky


On Tue, Jun 25, 2013 at 11:11 AM, Dobri <dyordan1 at ramapo.edu> wrote:
> Kind of hard to debug your code having no idea what version of wordpress you're using. Someone would have to download your thing and run it himself to figure out what's going on. A version number would be helpful for on-the-fly debugging.
>
> Also, Xdebug.
>
> http://xdebug.org/
>
> ~Dobri
>
> On Tue, 25 Jun 2013, at 1:55 PM, Micky Hulse wrote:
>
>> Hello,
>>
>> Currently, I have a setup for custom widgets where I create a simple
>> class for each new widget. For example:
>>
>> class.widget_1.php
>> class.widget_2.php
>> class.widget_3.php
>> ...
>>
>> 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:
>>
>> <https://gist.github.com/mhulse/5860561>
>>
>> Inspired by WPAlchemy, I thought it would be cool to create my custom
>> widgets like so:
>>
>> [code]
>>
>> $medium_rectangle_1 = new foo_Widget(
>>    array(
>>        'id_base' => 'medium_rectangle_1',
>>        'name' => 'Medium Rectangle 1',
>>        'description' => 'Standard Advertising Unit',
>>        'template' => STYLESHEETPATH .
>> '/includes/widgets/medium-rectangle-1.php',
>>    )
>> );
>>
>> [/code]
>>
>> Unfortunately, I keep getting this PHP notice:
>>
>> [snip]
>>
>> 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
>> 777
>>
>> [/snip]
>>
>> ... 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?
>>
>> Thanks!
>> M
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



-- 
http://hulse.me


More information about the wp-hackers mailing list