Class My_Widget1 extends WP_Widget{
public function __construct() {
$widget_ops = array(
'classname' => 'my_widget2',
'description' => 'My Widget is awesome',
);
parent::__construct( 'my_widget2', 'My Widget', $widget_ops );
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// outputs the content of the widget
$out_html='<h1>my title is '.$instance['title'].'</h1>';
echo $out_html;
}
/**
* Outputs the options form on admin
*
* @param array $instance The widget options
*/
public function form( $instance ) {
$title=empty($instance['title']) ? 'hello word' : $instance['title'];
echo '<input type="text" name="'.$this->get_field_name('title').'" value="'.$title.'" />';
}
/**
* Processing widget options on save
*
* @param array $new_instance The new options
* @param array $old_instance The previous options
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
$instance=[];
$instance['title']=$new_instance['title'];
return $instance;
}
}
add_action('widgets_init',function(){
register_widget('my_widget1');
});