So I'm working on my first plugin which allows the user to select from a dropdown list in the widget control panel.
The widget works fine in that the option is executed. Unfortunately the option they chose no longer shows in the control panel it reverts back to the default option.
I'm using the 2.8 API & I never learned the previous method.
Any suggestion on how I'd fix this?
Here's what I think are the relevant sections of the code:PHP Code:/**
* How to display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );
$style = $instance['style'];
PHP Code:/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['style'] = $new_instance['style'];
return $instance;
}
PHP Code:function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => '', 'image' => '', 'link' => '', 'link_text' => '', 'id' =>'', 'style' => '');
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<!-- Style: Select Box -->
<p>
<label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e('style:', ''); ?></label>
<select id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat" style="width:100%;">
<option <?php if ( 'standard' == $instance['style'] ) echo 'selected="selected"'; ?>>Standard-Box</option>
<option <?php if ( 'box2' == $instance['style'] ) echo 'selected="selected"'; ?>>Box-Type-2</option>
<option <?php if ( 'box3' == $instance['style'] ) echo 'selected="selected"'; ?>>Box-Type-3</option>
<option <?php if ( 'box4' == $instance['style'] ) echo 'selected="selected"'; ?>>Box-Type-4</option>
<option <?php if ( 'box5' == $instance['style'] ) echo 'selected="selected"'; ?>>Box-Type-5</option>
<option <?php if ( 'box6' == $instance['style'] ) echo 'selected="selected"'; ?>>Box-Type-6</option>
</select>
</p>
<?php
}


LinkBack URL
About LinkBacks
Reply With Quote
