<?php
// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('Contact Widget', 'cyclone-corporate'), 

// Widget description
array( 'description' => __( 'Footer widget for Address, Telephone & Email', 'cyclone-corporate' ), ) 
);
}

// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$address = apply_filters( 'widget_title', $instance['address'] );
$tel = apply_filters( 'widget_title', $instance['tel'] );
$email = apply_filters( 'widget_title', $instance['email'] );

// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $address ) || ! empty( $tel ) || ! empty( $email ) || ! empty( $title ) )
echo '<h3>'.esc_attr($title).'</h3>'. '<ul>'
.'<li>'.'<i class="fa fa-location-arrow"></i>'.' '.esc_attr($address).'</li>'. 
'<li>'.'<i class="fa fa-phone"></i>'.' '.esc_attr($tel).'</li>'.
'<li>'.'<i class="fa fa-envelope-o"></i>'.' '.esc_attr($email).'</li>'.'</ul>'.$args['after_title'];
}
		
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => 'Contact' ) );
$title = $instance[ 'title' ];
}
else {
$title = __( 'Contact', 'cyclone-corporate' );
}
if ( isset( $instance[ 'address' ] ) ) {
$address = $instance[ 'address' ];
}
else {
$address = __( 'New Address', 'cyclone-corporate' );
}
if ( isset( $instance[ 'tel' ] ) ) {
$tel = $instance[ 'tel' ];
}
else {
$tel = __( 'New Phone', 'cyclone-corporate' );
}
if ( isset( $instance[ 'email' ] ) ) {
$email = $instance[ 'email' ];
}
else {
$email = __( 'New Email','cyclone-corporate' );
}

// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget Title:','cyclone-corporate' ); ?></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 ); ?>" />
<label for="<?php echo $this->get_field_id( 'address' ); ?>"><?php _e( 'Address:','cyclone-corporate' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'address' ); ?>" name="<?php echo $this->get_field_name( 'address' ); ?>" type="text" value="<?php echo esc_attr( $address ); ?>" />
<label for="<?php echo $this->get_field_id( 'tel' ); ?>"><?php _e( 'Telephone:','cyclone-corporate' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'tel' ); ?>" name="<?php echo $this->get_field_name( 'tel' ); ?>" type="text" value="<?php echo esc_attr( $tel ); ?>" />
<label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php _e( 'Email:','cyclone-corporate' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'email' ); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />

</p>

<?php 
}
	
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['address'] = ( ! empty( $new_instance['address'] ) ) ? strip_tags( $new_instance['address'] ) : '';
$instance['tel'] = ( ! empty( $new_instance['tel'] ) ) ? strip_tags( $new_instance['tel'] ) : '';
$instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';

return $instance;
}
} // Class wpb_widget ends here

// Register and load the widget
function wpb_load_widget() {
	register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );