I've been following along a Lynda.com tutorial on plugin development and copied the plugin in the video to get an understanding of how they work. When I try to save the simple widget which basically just puts a title and some text in a widget area.
Following the code from the tutorial found here (Chapter 4) this is what I have.
class SimpleWidget extends WP_Widget
{
function SimpleWidget()
{
$widget_options = array(
'classname' => 'simple-widget',
'description' => 'Just a simple widget'
);
parent::WP_Widget('simple_widget','Simple Widget', $widget_options);
}
function widget($args, $instance)
{
extract($args, EXTR_SKIP);
$title = ($instance['title']) ? $instance['title'] : 'A Simple Widget';
$body = ($instance['body']) ? $instance['body']: 'A simple message';
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<p><?php echo $body; ?></p>
<?php
}
function form( $instance )
{
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">
Title: </label><br />
<input id="<?php echo $this->get_field_id('title'); ?>"
name="<?php $this->get_field_name('title'); ?>"
value="<?php echo esc_attr($instance['title']); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('body'); ?>">Body:</label><br />
<textarea id="<?php echo $this->get_field_id('body'); ?>"
name="<?php $this->get_field_name('body'); ?>" ><?php echo esc_attr($instance['body']); ?></textarea></p>
<?php
}
}
function simple_widget_init()
{
register_widget("SimpleWidget");
}
add_action('widgets_init', 'simple_widget_init');
?>
In the video, he mentions that by removing function update() the widget will still update...and in the video it does...but when I try so save text in the widget, it doesn't work...it just comes back blank.
I have also tried adding function update() as shown below with no luck either:
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['body'] = strip_tags( $new_instance['body'] );
return $instance;
}
Any suggestions for a beginning plugin developer why this isn't saving at all?
Other pertinent information Wordpress Build: 3.3.1
EDIT: Fixed an erroneous line of pasted code.