Simple Contact Widget

functions.php


<?php
 /*
 * Contact information widget
 */
 add_action( 'widgets_init', 'medics_widget_contact_info' );

function medics_widget_contact_info() {
 register_widget('medics_contact_info_widget');
 }

class medics_contact_info_widget extends WP_Widget {

function medics_contact_info_widget() {
 $medics_widget_ops = array( 'classname' => 'medics_info', 'description' => __('A widget that displays the title,contact information and socia links. ', 'medics_info') );

$medics_control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'medics_contact_info_widget' );

$this->WP_Widget( 'medics_contact_info_widget', __('Medics Contact Information', 'medics_info'), $medics_widget_ops, $medics_control_ops );
 }

function widget( $medics_args, $medics_instance ) {
 extract( $medics_args );

//Our variables from the widget settings.
 $medics_title = apply_filters('widget_title', $medics_instance['title'] );
 $medics_address = $medics_instance['address'];
 $medics_country = $medics_instance['country'];

$medics_phone = $medics_instance['phone'];
 $medics_fax = $medics_instance['fax'];
 $medics_email = $medics_instance['email'];
 $medics_website = $medics_instance['website'];

echo $before_widget;

Display widget
?>
<h1><?php if(!empty($medics_instance[‘title’])) echo $medics_instance[‘title’]; else echo “Contributor”; ?></h1>
<div class=”footer-title-line”></div>
<div class=”contct-widget”>
<?php if(!empty($medics_instance[‘address’])) { ?>
<p><?php echo $medics_instance[‘address’]; ?>

<?php if(!empty($medics_instance[‘country’])) { ?>
<?php echo “,”.$medics_instance[‘country’]; ?>
<?php } ?>
</p>
<?php } ?>
<?php if(!empty($medics_instance[‘phone’])) { ?>
<p>Phone: <?php echo $medics_instance[‘phone’]; ?></p>
<?php } ?>

<?php if(!empty($medics_instance[‘fax’])) { ?>
<p>Fax: <?php echo $medics_instance[‘fax’]; ?></p>
<?php } ?>

<?php if(!empty($medics_instance[’email’])) { ?>
<p>Email: <a href=”mailto:<?php echo $medics_instance[’email’]; ?>”><?php echo $medics_instance[’email’]; ?></a></p>
<?php } ?>

<?php if(!empty($medics_instance[‘website’])) { ?>
<p>Web: <a href=”<?php echo esc_url($medics_instance[‘website’]); ?>”><?php echo esc_url($medics_instance[‘website’]); ?></a></p>
<?php } ?>
</div>

<?php
echo $after_widget;
}

//Update the widget

function update( $new_instance, $old_instance ) {
$medics_instance = $old_instance;

//Strip tags from title and name to remove HTML
$medics_instance[‘title’] = strip_tags( $new_instance[‘title’] );
$medics_instance[‘address’] = strip_tags( $new_instance[‘address’] );
$medics_instance[‘country’] = strip_tags( $new_instance[‘country’] );
$medics_instance[‘phone’] = strip_tags( $new_instance[‘phone’] );
$medics_instance[‘fax’] = strip_tags( $new_instance[‘fax’] );
$medics_instance[‘website’] = esc_url_raw(strip_tags( $new_instance[‘website’]));
$medics_instance[’email’] = sanitize_email(strip_tags( $new_instance[’email’] ));

return $medics_instance;
}

function form( $medics_instance ) {
?>
<p>
<label for=”<?php echo $this->get_field_id( ‘title’ ); ?>”>
<?php _e(‘Widget Title:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘title’ ); ?>” name=”<?php echo $this->get_field_name( ‘title’ ); ?>” value=”<?php if(!empty($medics_instance[‘title’])) { echo $medics_instance[‘title’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ‘address’ ); ?>”>
<?php _e(‘Address:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘address’ ); ?>” name=”<?php echo $this->get_field_name( ‘address’ ); ?>” value=”<?php if(!empty($medics_instance[‘address’])) { echo $medics_instance[‘address’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ‘country’ ); ?>”>
<?php _e(‘Country:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘country’ ); ?>” name=”<?php echo $this->get_field_name( ‘country’ ); ?>” value=”<?php if(!empty($medics_instance[‘country’])) { echo $medics_instance[‘country’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ‘phone’ ); ?>”>
<?php _e(‘Phone:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘phone’ ); ?>” name=”<?php echo $this->get_field_name( ‘phone’ ); ?>” value=”<?php if(!empty($medics_instance[‘phone’])) { echo $medics_instance[‘phone’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ‘fax’ ); ?>”>
<?php _e(‘Fax:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘fax’ ); ?>” name=”<?php echo $this->get_field_name( ‘fax’ ); ?>” value=”<?php if(!empty($medics_instance[‘fax’])) { echo $medics_instance[‘fax’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ’email’ ); ?>”>
<?php _e(‘Email Address:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ’email’ ); ?>” name=”<?php echo $this->get_field_name( ’email’ ); ?>” value=”<?php if(!empty($medics_instance[’email’])) { echo $medics_instance[’email’]; } ?>” style=”width:100%;” />
</p>
<p>
<label for=”<?php echo $this->get_field_id( ‘website’ ); ?>”>
<?php _e(‘Website:’, ‘medics_info’); ?>
</label>
<input id=”<?php echo $this->get_field_id( ‘website’ ); ?>” name=”<?php echo $this->get_field_name( ‘website’ ); ?>” value=”<?php if(!empty($medics_instance[‘website’])) { echo $medics_instance[‘website’]; } ?>” style=”width:100%;” />
</p>
<?php
}
}

?>

[/code]

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: