[wp-hackers] Widget definitions inside classes

Alex King lists at alexking.org
Sat Aug 26 14:02:40 GMT 2006


For my Popularity Contest plugin I created a nice neat class, then  
added functions for all the methods I needed to call from hooks:

function foo() {
	global $my;
	$my->foo();
}

Not really an elegant solution, but not the worst thing in the world  
either as the functions require zero maintenance.

Cheers,
--Alex

Personal   http://alexking.org
Business   http://kingdesign.net


On Aug 25, 2006, at 7:56 PM, Jamie Talbot wrote:

> Hi,
>
> I'd like to keep code to define a widget and its control neatly  
> inside a class definition, but it
> doesn't seem to be possible.  Has anyone found a way to do this?   
> There doesn't seem to be a
> mechanism for doing so, like exists for filters and actions.
>
> register_sidebar_widget('Languages', 'MyClass::my_language_widget');
>
> doesn't work, and would be no good anyway as it would be a static  
> function and there's no $this
> available.
>
> register_sidebar_widget('MyWidget', array(& $this, 'my_widget'));
>
> like
>
> add_filter('the_content', array(& $this, 'my_the_content_filter'));
>
> would be useful.
>
> Cheers,
>
> Jamie.
>
>
> --
> http://jamietalbot.com



More information about the wp-hackers mailing list