Widgets redesign
All of the redesigned widgets functionality is in place in trunk. Only remaining is some improvement to the visual design for the widgets screen in admin.
The new way to add widgets to WordPress is by extending WP_Widget. All widgets created that way have support for multiple instances.
Also all existing widgets will have to be converted to this system as the previous API functions will (most likely) be removed in 2.9. This is quite easy and any of the default widgets can be used as an example.
A typical widget is constructed as follows:
class WP_Widget_Archives extends WP_Widget {
function WP_Widget_Archives() {
$widget_ops = array('classname' => 'widget_archive', 'description' => __( "A monthly archive of your blog's posts") );
$this->WP_Widget(false, __('Archives'), $widget_ops);
}
function widget( $args, $instance ) {
// displays the widget on the front end
}
function update( $new_instance, $old_instance ) {
// update the instance's settings
}
function form( $instance ) {
// displays the widget admin form
}
}
// register the widget
add_action('widgets_init', 'my_super_widget_init');
function my_super_widget_init() {
register_widget('WP_Widget_Archives');
}
For more details and examples check wp-includes/widgets.php and wp-includes/default-widgets.php.
GaMerZ 5:26 am on April 22, 2009 Permalink
I think you miss out the register_widget() hook.
http://lesterchan.net/wordpress/2009/03/17/new-wp_widget-class-in-wordpress-28/
Andrew Ozz 6:17 am on April 22, 2009 Permalink
You’re right, that should be in there too.
amfprod 4:24 am on April 27, 2009 Permalink
While we’re at it can we give widgets a RTE?
WordPress News: WordPressMU Updated, WordPress 2.8 News, WP.com, WordPress Events | BlogIT 9:23 am on April 27, 2009 Permalink
[...] Redesigned Finally: The long awaited redesign of the WordPress Widgets are in the Appearance panel is done and undergoing testing. Some visual improvements are needed, [...]
Denis de Bernardy 7:52 am on April 28, 2009 Permalink
It’s really neat, but… Grumble, grumble. Now, I need to rewrite over a dozen plugins that used the old API. I really hope WP 2.8 won’t be released too early.
Viper007Bond 12:13 pm on April 28, 2009 Permalink
Old widgets will continue to work fine in WordPress 2.8.
WordPress News: BuddyPress News, WordPress 2.8 News, WordCamp Toronto & Virginia, WordPress.tv Feeds, and More | The Blog Herald 11:02 pm on May 7, 2009 Permalink
[...] Redesigned Finally: The long awaited redesign of the WordPress Widgets are in the Appearance panel is done and undergoing testing. Some visual improvements are needed, [...]