Skip to content

Instantly share code, notes, and snippets.

@DouglasdeMoura
Last active April 14, 2016 20:19
Show Gist options
  • Save DouglasdeMoura/b9fe22b67bcfe19b65ed1d14a8d5a64e to your computer and use it in GitHub Desktop.
Save DouglasdeMoura/b9fe22b67bcfe19b65ed1d14a8d5a64e to your computer and use it in GitHub Desktop.
Template to create WordPress Widgets
<?php
class My_Widget extends WP_Widget {
/**
* Sets up the widgets name etc
*/
public function __construct() {
$widget_ops = array(
'classname' => 'my_widget',
'description' => __( 'My Widget is awesome', 'domain' ),
);
parent::__construct( 'my_widget', __( 'My Widget', 'domain'), $widget_ops );
}
/**
* Set the default args
*/
public function defaults() {
return array(
'title' => __( 'Default', 'domain' ),
'text' => __( 'Text', 'domain' )
);
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
}
/**
* Outputs the options form on admin
*
* @param array $instance The widget options
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->defaults() );
}
/**
* 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 ) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment