[wp-hackers] New Widgets API
Joost de Valk
joost at yoast.com
Fri Mar 27 06:00:22 GMT 2009
Bless you Ryan, great work!
Ryan Boren wrote:
> In trunk is a new widgets API. WP_Widget is a class that abstracts
> away much of the complexity involved in writing a widget, especially
> multi-widgets. Basically, you extend WP_Widget with your own class
> that provides a constructor and three methods -- widget(), form(), and
> update(). widget() outputs the actual content of the widget.
> update() processes options to be saved. form() outputs the options
> form. A widget is registered by passing the name of the widget class
> to register_widget(). All widgets written with WP_Widget are multiple
> instance capable. Options for old single-instance widgets ported to
> WP_Widget will be upgraded to the new multi-option storage format,
> which is simply a multi-dimensional array keyed by instance ID.
> Options for widgets using the old multi-instance pattern should work
> as is. If your widget has custom option storage needs, you can
> provide your own get_settings() and save_settings() methods.
> The WP_Widget source can be viewed here (read the phpdoc for more
> info on usage):
> You can see examples of how to use it here:
> If you author any widgets, try porting them to WP_Widget and give your
> feedback on what can be improved. The trac ticket is:
> (Props to the MultiWidget class, on which WP_Widget is based:
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers