[wp-hackers] Need WP/PHP guru eyeballs/feedback on my WP_Widget wrapper class
J.D. Grimes
jdg at codesymphony.co
Sat Jun 29 13:04:41 UTC 2013
Hi Micky,
You need to register the widget with the register_widget() function like this:
function myplugin_register_widgets() {
register_widget( 'Foo_Widget_2' );
}
add_action( 'widgets_init', 'myplugin_register_widgets' );
Then it should work.
-J.D.
On Jun 28, 2013, at 6:52 PM, Micky Hulse <mickyhulse.lists at gmail.com> wrote:
> On Tue, Jun 25, 2013 at 5:33 PM, J.D. Grimes <jdg at codesymphony.co> wrote:
>> Hey Micky, I was thinking about this and I think I've found a good solution for you. Just extend the Foo_Widget class with child classes like this:
>
> Hi J.D.,
>
> I finally had a chance to test your suggestion using my test
> Foo_Widget class. Unfortunately, I'm getting the same results as
> before.
>
> [snip]
>
> include_once('class.foo_widget.php');
>
> class Foo_Widget_2 extends Foo_Widget {
>
> function __construct() {
>
> parent::__construct(
> array(
> 'id_base' => 'foo_test_widget',
> 'name' => 'Foo Test Widget',
> )
> );
>
> }
> }
>
> new Foo_Widget_2();
>
> [/snip]
>
> The above gets include_once into my functions.php.
>
> This is the Foo_Widget() class (same one from before):
>
> <https://gist.github.com/mhulse/5861847>
>
> When I test the above code, I just see an empty widget under
> "Available Widgets". When inspecting with Firebug, neither "id_base"
> or "name" made it through.
>
> If it's not too much trouble, could you confirm that the code you are
> using is the same as the stuff I'm using?
>
> If you got it to work, I must be doing something wrong (or, maybe I
> need to upgrade to the latest WP? We're one version behind).
>
> Thanks so much! I owe you one! :-)
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list