When you are building a widget using the widget class, your widget needs to have the following structure:
class UNIQUE_WIDGET_NAME extends WP_Widget { public function __construct() { $widget_ops = array(); $control_ops = array(); parent::__construct('base id', 'name', $widget_ops, $control_ops); } public function widget($args, $instance) { // used when the sidebar calls the widget } public function form($instance) { // prints the form on the widgets page } public function update($new_instance, $old_instance) { // used when the user saves his/her widget options } } // initiate the widget // register the widget
My unique widget name for this project is KK_Widget_Tag_Cloud. Now, let's go over each of the preceding functions one by one and understand what's going on.