Skip to content

Instantly share code, notes, and snippets.

@bavington
Created July 29, 2013 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bavington/6106687 to your computer and use it in GitHub Desktop.
Save bavington/6106687 to your computer and use it in GitHub Desktop.
Boilerplate for creating a simple Widget Plugin in Wordpress.
<?php
/*
Plugin Name: My Widget Plugin
Plugin URI: http://twitter.com/jamesbavington
Description: A simple plugin that adds a simple widget
Version: 0.1
Author: bavington
Author URI: http://twitter.com/jamesbavington
License: GPL2
*/
class wp_my_plugin extends WP_Widget {
// constructor
function wp_my_plugin() {
/* ... */
}
// widget form creation
function form($instance) {
/* ... */
}
// widget update
function update($new_instance, $old_instance) {
/* ... */
}
// widget display
function widget($args, $instance) {
extract( $args );
echo $before_widget; // pre-widget code from theme
/* ... */
echo $after_widget; // post-widget code from theme
}
}
// register widget
add_action('widgets_init', create_function('', 'return register_widget("wp_my_plugin");'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment