教程中并不完全清楚,但是add_action()
调用应该在类之外。
class My_gCal_Widget extends WP_Widget {
public function __construct() {
parent:: __construct(
\'my_gcal_widget\',
\'My_gCal_Widget\',
array(
\'classname\' => \'my-gcal-widget\',
\'description\' => \'Shows events from a calendar\'
)
);
}
public function widget($args, $instance) { }
}
add_action(\'widgets_init\', function() {
register_widget(\'My_gCal_Widget\');
});