Unexpected add action function in WP plugin

It’s not entirely clear in the tutorial, but the add_action() call should be outside the class. 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’); });