<?php
//
// Example MultiWidget. Use this as a template for your own.
//
class ExampleMultiWidget extends MultiWidget
{
function ExampleMultiWidget()
{
$this->MultiWidget(
'example-multi', // id_base
'ExampleMulti', // name
array('description'=>__
('Widget which allows multiple instances'))
);
}
// Echo the actual widget content. Subclasses should over-ride this function
// to generate their widget code.
function widget($args,$instance)
{
echo $before_widget;
echo $before_title . $instance['title'] . $after_title;
echo $instance['content'];
echo $after_widget;
}
// Update a particular instance.
// This function should check that $new_instance is set correctly.
// The newly calculated value of $instance should be returned.
function control_update($new_instance, $old_instance)
{
if( !isset($new_instance['title']) ) // user clicked cancel
return false;
$instance = $old_instance;
$instance['title'] = wp_specialchars( $new_instance['title'] );
$instance['content'] = wp_specialchars( $new_instance['content'] );
return $instance;
}
// Echo a control form for the current instance.
// The form has inputs with names like widget-ID_BASE[$number][FIELD_NAME]
// so that all data for that instance of the widget are stored in one
// $_POST variable: $_POST['widget-ID_BASE'][$number]
function control_form($instance)
{
?>
<p>
<label for="<?php echo $this->get_field_id('title') ?>">
<?php _e('Title:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('title') ?>"
name="<?php echo $this->get_field_name('title') ?>" type="text"
</label>
<label for="<?php echo $this->get_field_id('content') ?>">
<?php _e('Content:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('content') ?>"
name="<?php echo $this->get_field_name('content') ?>" type="text"
</label>
<input type="hidden" id="<?php echo $this->get_field_id('submit') ?>"
name="<?php echo $this->get_field_name('submit') ?>" value="1" />
</p>
<?php
}
} // end class ExampleMultiWidget
// Finally create an object for the widget-type and register it.
$example_multi = new ExampleMultiWidget();
add_action
( 'widgets_init', array($example_multi,'register') );
?>