All widgets have at least one option: a title.
So, about the most basic possible widget:
PHP Code:
<?php
class WP_Widget_Basic extends WP_Widget {
function WP_Widget_Basic() {
$widget_ops = array('classname' => 'widget_basic', 'description' => 'Basic Widget, no options except title' );
$this->WP_Widget('basic', 'Basic', $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? 'Basic' : $instance['title']);
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
?>
<p> BASIC! </p>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = strip_tags($instance['title']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Title:</label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<?php
}
}
Replace the BASIC! with whatever you like.
You'll still need to call register_widget() at widgets_init and such.
Okay, technically, you could simplify it by hardcoding a title and such, but the interface would look weird. And having a configurable title is a good thing anyway.