Custom social media widget

class Social_Widget extends WP_Widget {

public function __construct() {
parent::__construct(‘Social_Widget’, __(‘Social Media Footer Widget’), array( ‘description’ => __( ‘Sample Social Media widget based on Custom Widget’), ) );
}

public function form($instance) {

if( $instance) {
$title = esc_attr($instance[‘title’]);
$facebook = esc_attr($instance[‘facebook’]);
$twitter = esc_attr($instance[‘twitter’]);
$linkedin = esc_attr($instance[‘linkedin’]);
$delecious = esc_attr($instance[‘delecious’]);

} else {
$title = ”;
$facebook = ”;
$twitter = ”;
$linkedin = ”;
$delecious = ”;
}
?>

<p>
<label for=”<?php echo $this->get_field_id(‘title’); ?>”><?php _e(‘Title’, ‘smbw-language’); ?></label>
<input id=”<?php echo $this->get_field_id(‘title’); ?>” name=”<?php echo $this->get_field_name(‘title’); ?>” value=”<?php echo $instance[‘title’]; ?>”/>

</p>

<h3><img src=”<?php echo plugins_url(‘social-media-badge-widget/images/facebook.png’); ?>” /> <?php _e(‘Facebook’, ‘smbw-language’); ?></h3>
<p>
<label for=”<?php echo $this->get_field_id(‘facebook’); ?>”><?php _e(‘Business Page’, ‘smbw-language’); ?></label>
<input id=”<?php echo $this->get_field_id(‘facebook’); ?>” name=”<?php echo $this->get_field_name(‘facebook’); ?>” value=”<?php echo $instance[‘facebook’]; ?>” style=”width:90%;” />
<span><?php _e(‘Insert the business page URL (the part at the end, after facebook.com/’, ‘smbw-language’); ?></span>
</p>

<h3><img src=”<?php echo plugins_url(‘social-media-badge-widget/images/twitter.png’); ?>” /> <?php _e(‘Twitter’, ‘smbw-language’); ?></h3>
<p>
<label for=”<?php echo $this->get_field_id(‘twitter’); ?>”><?php _e(‘Username’, ‘smbw-language’); ?></label>
<input id=”<?php echo $this->get_field_id(‘twitter’); ?>” name=”<?php echo $this->get_field_name(‘twitter’); ?>” value=”<?php echo $instance[‘twitter’]; ?>” style=”width:90%;” />
<span><?php _e(‘Insert without the \’@\’.’, ‘smbw-language’); ?></span>
</p>

<h3><img src=”<?php echo plugins_url(‘social-media-badge-widget/images/linkedin.png’); ?>” /> <?php _e(‘LinkedIn’, ‘smbw-language’); ?></h3>
<p>
<label for=”<?php echo $this->get_field_id(‘linkedin’); ?>”><?php _e(‘Company ID’, ‘smbw-language’); ?></label>
<input id=”<?php echo $this->get_field_id(‘linkedin’); ?>” name=”<?php echo $this->get_field_name(‘linkedin’); ?>” value=”<?php echo $instance[‘linkedin’]; ?>” style=”width:90%;” />
<span><?php _e(‘Insert company ID, get ID ‘, ‘smbw-language’); ?><a href=”https://developer.linkedin.com/plugins/company-profile-plugin&#8221; target=”_blank”><?php _e(‘here ‘, ‘smbw-language’); ?></a><?php _e(‘ by typing in your company name then press get code. Finally, find the ID in the code.’, ‘smbw-language’); ?></span>
</p>

<h3><img src=”<?php echo plugins_url(‘images/icon4.jpg’); ?>” /> <?php _e(‘Delicious’, ‘smbw-language’); ?></h3>
<p>
<label for=”<?php echo $this->get_field_id(‘delecious’); ?>”><?php _e(‘User ID’, ‘smbw-language’); ?></label>
<input id=”<?php echo $this->get_field_id(‘delecious’); ?>” name=”<?php echo $this->get_field_name(‘delecious’); ?>” value=”<?php echo $instance[‘delecious’]; ?>” style=”width:90%;” />
<span><?php _e(‘Insert user ID including the bit after the \’@\’.’, ‘smbw-language’); ?></span>
</p>
<?php
}

public function update($new_instance, $old_instance) {
$instance = $old_instance;

/* Strip tags (if needed) and update the widget settings. */
$instance[‘title’] = sanitize_text_field($new_instance[‘title’]);
$instance[‘facebook’] = sanitize_text_field($new_instance[‘facebook’]);
$instance[‘twitter’] = sanitize_text_field($new_instance[‘twitter’]);
$instance[‘linkedin’] = sanitize_text_field($new_instance[‘linkedin’]);
$instance[‘delecious’] = sanitize_text_field($new_instance[‘delecious’]);
return $instance;
}

// display widget
public function widget($args, $instance) {
extract( $args );
// these are the widget options
$title = apply_filters(‘widget_title’, $instance[‘title’]);
$facebook = $instance[‘facebook’];
$twitter = $instance[‘twitter’];
$linkedin = $instance[‘linkedin’];
$delecious = $instance[‘delecious’];
echo $before_widget;
// Display the widget
echo ‘<div>’;

// Check if title is set
if ( $title ) {
// echo $before_title . $title . $after_title;
}

// Check if text is set
if( $facebook ) {
echo ‘<li><a href=”https://facebook.com/&#8217;.$facebook.'”><img src=”http://localhost/customizr/wp-content/uploads/2014/03/icon1.jpg”>Facebook</a></li>&#8217;;
}
if( $twitter ) {
echo ‘<li><a href=”https://twitter.com/&#8217;.$twitter.'”><img src=”http://localhost/customizr/wp-content/uploads/2014/03/icon2.jpg”>Twitter</a></li>&#8217;;
}
if( $linkedin ) {
echo ‘<li><a href=”https://linkedin.com/&#8217;.$linkedin.'”><img src=”http://localhost/customizr/wp-content/uploads/2014/03/icon3.jpg”>Linkedin</a></li>&#8217;;
}
if( $delecious ) {
echo ‘<li><a href=”https://delecious.com/&#8217;.$delecious.'”><img src=”http://localhost/customizr/wp-content/uploads/2014/03/icon4.jpg”>Delecious</a></li>&#8217;;
}

echo ‘</div>’;
echo $after_widget;
}

}
register_widget( ‘Social_Widget’ );

Advertisements

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