Created
December 14, 2011 19:22
-
-
Save matiskay/1478047 to your computer and use it in GitHub Desktop.
Wordpress Widget Skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Widget_Name extends WP_Widget { | |
function Widget_Name() { | |
$widget_opts = array( | |
'classname' => 'your-awesome-class', | |
'description' => 'Your awesome Description', | |
); | |
$this->WP_Widget('your_awesome_cool_name', 'Awesome Title', $widget_opts); | |
} | |
// widget outputs the widget content. | |
function widget($args, $instance) { | |
} | |
// displays the form which shows on the Widgets management panel. | |
function form($instance) { | |
$output = ''; | |
$instance = (array) $instance; | |
$instance = wp_parse_args($instance, array('number' => 2 )); | |
$title = esc_attr($instance['title']); | |
// More Code | |
echo $output; | |
} | |
// updates the widget options when saved. | |
function update($new_instance, $old_instance) { | |
$instance = $old_instance; | |
$instance['title'] = strip_tags($new_instance['title']); | |
return $instance; | |
} | |
} | |
// Load and Register the widget | |
add_action('widgets_init', 'awesome_plugin_name_load_widgets'); | |
function awesome_plugin_name_load_widgets() { | |
register_widget('Widget_Name'); | |
} |
Hi, $this->WP_Widget() is deprecated so use parent::__construct() instead of $this->WP_Widget().
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks matiskay