dddobriak
9/30/2016 - 11:31 PM

basic custom widget

basic custom widget

class Widget_Class_Name extends WP_Widget {

  /**
   * Sets up the widgets name etc
   */
  public function __construct() {
    $widget_ops = array( 
      'classname' => 'widget_class_name',
      'description' => 'Custom Widget Name',
    );
    parent::__construct( 'widget_class_name', 'Custom Widget Name', $widget_ops );
  }

  /**
   * Outputs the content of the widget
   *
   * @param array $args
   * @param array $instance
   */
  public function widget( $args, $instance ) {
    echo $args['before_widget'];
      my_custom_function();
    echo $args['after_widget'];
  }

  /**
   * Outputs the options form on admin
   *
   * @param array $instance The widget options
   */
  public function form( $instance ) {
    // outputs the options form on admin
    echo '<p></p>';
  }

  /**
   * 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
  }
}

add_action( 'widgets_init', function(){
  register_widget( 'Widget_Class_Name' );
});