Following a tutorial and it works fine. I just can't understand how update method saves $instance array in the database from Select tag? You can choose default or full, slick save in the admin area and it saves in the db.
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo '<div class="g-ytsubscribe"
data-layout="'.$instance['data_layout'].'"
data-count="default">
</div>';
echo $args['after_widget'];
}
public function form( $instance ) {
$data_layout = ! empty( $instance['data_layout'] ) ? $instance['data_layout'] : esc_html__( 'default', 'yts_domain' );
?>
<select class="widefat"
<option value="default" <?php echo ($data_layout == 'default' ? 'selected' : ''); ?>>Default</option>
<option value="full" <?php echo ($data_layout == 'full' ? 'selected' : ''); ?>>Full</option>
</select>
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['data_layout'] = ( ! empty( $new_instance['data_layout'] ) ) ? sanitize_text_field( $new_instance['data_layout'] ) : '';
return $instance;
}