Where do we add our custom widget? I keep on getting internal errors, I tried to add the class in wp_content > plugins, or wp_includes > widgets, but I get an internal error.
The class is simple, inside "My_Widget.php" :
<?php
/*
Plugin Name: My_Widget
Description: my widet description
Author: Author
*/
class My_Widget extends WP_Widget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
$widget_ops = array(
'class_name' => 'my_widget',
'description' => 'My Widget is awesome',
);
parent::__construct( 'my_widget', '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
}
/**
* Outputs the options form on admin
*
* @param array $instance The widget options
*/
public function form( $instance ) {
// outputs the options form on admin
}
/**
* Processing widget options on save
*
* @param array $new_instance The new options
* @param array $old_instance The previous options
*/
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
}
Then in my functions.php :
register_widget( 'My_Widget' );