In $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' );
id_base should be without space and in your rollover image, your name is wrong, you have the name set to echo $this->get_field_name( 'image' );
when it should be echo $this->get_field_name( 'rollover_image' );
add_action ( 'widgets_init' , 'my_widget' ) ;
function my_widget () {
register_widget ( 'MY_Widget' ) ;
}
class MY_Widget extends WP_Widget {
function MY_Widget () {
$widget_ops = array ( 'classname' => 'example' , 'description' => __ ( 'A widget that creates a rollover image effect with a hyperlink. ' , 'example' ) ) ;
$control_ops = array ( 'width' => 300 , 'height' => 350 ) ;
$this -> WP_Widget ( 'example-widget' , __ ( 'Example Widget' , 'example' ) , $widget_ops , $control_ops ) ;
}
function widget ( $args , $instance ) {
extract ( $args ) ;
//Our variables from the widget settings.
$link = apply_filters ( 'widget_link' , $instance[ 'link' ] ) ;
$image = $instance[ 'image' ] ;
$rollover_image = $instance[ 'rollover_image' ] ;
echo $before_widget ;
// Display the widget link
if ( $link )
echo $before_link . $link . $after_link ;
//Display the name
printf ( '<p>' . __ ( 'Hey their Sailor! My name is %1$s.' , 'example' ) . '</p>' , $image ) ;
printf ( '<p>' . __ ( 'Hey their Sailor! My name is %1$s.' , 'example' ) . '</p>' , $rollover_image ) ;
echo $after_widget ;
}
//Update the widget
function update ( $new_instance , $old_instance ) {
$instance = $old_instance ;
//Strip tags from link and name to remove HTML
$instance[ 'link' ] = strip_tags ( $new_instance[ 'link' ] ) ;
$instance[ 'image' ] = strip_tags ( $new_instance[ 'image' ] ) ;
$instance[ 'rollover_image' ] = strip_tags ( $new_instance[ 'rollover_image' ] ) ;
return $instance ;
}
function form ( $instance ) {
//Set up some default widget settings.
$defaults = array ( 'link' => 'Example' , 'image' => '/images/editorial.png' , 'rollover_image' => '/images/editorial.png' ) ;
$instance = wp_parse_args ( ( array ) $instance , $defaults ) ;
?>
<p>
<label for="<?php echo $this -> get_field_id ( 'link' ) ; ?>"><?php _e ( 'link' , 'example' ) ; ?></label>
<input id="<?php echo $this -> get_field_id ( 'link' ) ; ?>" name="<?php echo $this -> get_field_name ( 'link' ) ; ?>" value="<?php echo $instance[ 'link' ] ; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this -> get_field_id ( 'image' ) ; ?>"><?php _e ( 'image' , 'example' ) ; ?></label>
<input id="<?php echo $this -> get_field_id ( 'image' ) ; ?>" name="<?php echo $this -> get_field_name ( 'image' ) ; ?>" value="<?php echo $instance[ 'image' ] ; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this -> get_field_id ( 'rollover_image' ) ; ?>"><?php _e ( 'rollover_image:' , 'example' ) ; ?></label>
<input id="<?php echo $this -> get_field_id ( 'rollover_image' ) ; ?>" name="<?php echo $this -> get_field_name ( 'rollover_image' ) ; ?>" value="<?php echo $instance[ 'rollover_image' ] ; ?>" style="width:100%;" />
</p>
<?php
}
}