Okay so it works now.
The data from the name input is now displayed on front end along with the uploaded image.
I honestly can’t explain why…
but I basically just copied some lines from the tutorial link I posted and pasted it where it belongs and everything started to work the way it should.
Here is the new* code//
// widget class
class eotw_w extends WP_Widget {
function eotw_w() {
$widget_ops = array('classname' => 'eotw-w');
$this->WP_Widget('eotw-w-widget', 'Editor of the Week', $widget_ops);
}
function widget($args, $instance) {
extract($args);
$title = apply_filters('widget_title', $instance['title'] );
$name = $instance['name'];
$image_uri = $instance['image_uri'];
// widget content
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
if ( $name )
printf( '<p>' . __('This weeks EOTW is %1$s ', 'example') . '</p>', $name );
?>
<img class="eotw-edit" src="https://wordpress.stackexchange.com/questions/127321/<?php echo esc_url($instance["image_uri']); ?>" />
<?php
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['name'] = strip_tags( $new_instance['name'] );
$instance['image_uri'] = strip_tags( $new_instance['image_uri'] );
return $instance;
}
function form($instance) {
//Set up some default widget settings.
$defaults = array( 'title' => __('Editor of the Week', 'example'), 'name' => __('Bilal Shaheen', 'example'));
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id('name'); ?>">name</label><br />
<input type="text" name="<?php echo $this->get_field_name('name'); ?>" id="<?php echo $this->get_field_id('name'); ?>" value="<?php echo $instance['name']; ?>" class="widefat" />
</p>
<p>
<label for="<?php echo $this->get_field_id('image_uri'); ?>">Image</label><br />
<?php
if ( $instance['image_uri'] != '' ) :
echo '<img class="custom_media_image" src="' . $instance['image_uri'] . '" style="margin:0;padding:0;max-width:100px;float:left;display:inline-block" /><br />';
endif;
?>
<input type="text" class="widefat custom_media_url" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $instance['image_uri']; ?>" style="margin-top:5px;">
<input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="<?php echo $this->get_field_name('image_uri'); ?>" value="Upload Image" style="margin-top:5px;" />
</p>
<?php
}
}
?>