Someone mentioned to me that they couldn’t use PHP5-style object constructors when using the WP Widget API. I looked into it, and it turns out it does work. Example:
class My_Widget extends WP_Widget { function __construct() { $widget_ops = array( 'classname' => 'css-class', 'description' => 'Description' ); parent::__construct( 'css-class', 'Title', $widget_ops ); } // Rest of your widget subclass goes here }
The key is using parent::__construct()
instead of $this->WP_Widget()
.