[wp-hackers] New Widgets API

Ryan Boren ryan at boren.nu
Thu Mar 26 23:19:50 GMT 2009

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:

More information about the wp-hackers mailing list