Unable to save widget contents

I am having two widgets. They are created in the same file-widget.php . If i keep one widget only then it will work without any issues. But when they are together one will stop working(it will not be dragable).

My code is below.

class Widget_1 extends WP_Widget {

//setup the widget name, description, etc…
public function __construct() {

$widget_ops = array(
‘classname’ => ‘widget1’,
‘description’ => ‘Description’,
);
parent::__construct( ‘widget1’, ‘Widget 1’, $widget_ops );

}

//back-end display of widget
public function form( $instance ) {
echo ‘<p><strong>Some text here</p>’;
}

//front-end display of widget
public function widget( $args, $instance ) {

echo $args[‘before_widget’];

//there are fields in between this

echo $args[‘after_widget’];
}

}
add_action( ‘widgets_init’, function() {
register_widget( ‘Widget_1’ );
} );

class Widget_2 extends WP_Widget {

//setup the widget name, description, etc…
public function __construct() {

$widget_ops = array(
‘classname’ => ‘widget2’,
‘description’ => ‘Description’,
);
parent::__construct( ‘widget2’, ‘Widget 2’, $widget_ops );

}

//back-end display of widget
public function form( $instance ) {
echo ‘<p><strong>Sometext here</p>’;
}

//front-end display of widget
public function widget( $args, $instance ) {

echo $args[‘before_widget’];

//there are fields in between this

echo $args[‘after_widget’];
}

}
add_action( ‘widgets_init’, function() {
register_widget( ‘Widget_2’ );
} );

When i change the

public function form( $instance )

to

public function forms( $instance )

Both starts to work but save button wont show up for one plugin.

Thanks

Read more here:: Unable to save widget contents

Leave a Reply

Your email address will not be published. Required fields are marked *