Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

WidgetConstructor

WidgetConstructor

class my_widget extends WP_Widget {
    public function __construct () {
        // widget processes
        parent::__construct(
            'widget_ID',
            'widget_name',
            array( 'description' => __( 'A widget description', 'text_domain'), ) //Args
            );
    }
    
    /**
     * Widget front end 
    */
    public function widget( $args, $instance ) {
        // widget output
        extract( $args );
        $title = apply_filters( 'widget_title', $instance['title'] );
        
        echo $before_widget;
        if ( ! empty( $title ) ) {
            echo $before_title . $title . $after_title;
        }
        echo $widget_content;
        echo $after_widget;
    }
    // widget form
    public function form( $instance ) {
        // outputs the options form
        if ( isset( $instance[ 'title' ] ) ) {
            $title = $instance[ 'title' ];
        }
        else {
            $title = __( 'New Title', 'text_domain');
        } ?>
        <p>
        <label></label>
        <input />
        </p>
        <?php
        
    }
    public function update( $new_instance, $old_instance ) {
        // processes widget options
        $instance = array();
        $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
        return $instance;
    }
}