Advertisement
Guest User

Untitled

a guest
Mar 13th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <?php
  2.  
  3. // Social Widget
  4. class Theme_Widget_Social extends WP_Widget {
  5.  
  6. public $sites = array();
  7.  
  8. function Theme_Widget_Social()
  9. {
  10. $this->sites = array(
  11.  
  12. 'facebook' => array(
  13. 'icon' => 'icon-facebook-square',
  14. 'title' => __('Facebook URL', 'theme_admin'),
  15. ),
  16. 'twitter' => array(
  17. 'icon' => 'icon-twitter-square',
  18. 'title' => __('Twitter URL', 'theme_admin'),
  19. ),
  20. 'googleplus' => array(
  21. 'icon' => 'icon-google-plus-square',
  22. 'title' => __('Google+ URL', 'theme_admin'),
  23. ),
  24. 'linkedin' => array(
  25. 'icon' => 'icon-linkedin-square',
  26. 'title' => __('LinkedIn URL', 'theme_admin'),
  27. ),
  28. 'pinterest' => array(
  29. 'icon' => 'icon-pinterest',
  30. 'title' => __('Pinterest URL', 'theme_admin'),
  31. ),
  32. 'instagram' => array(
  33. 'icon' => 'icon-instagram',
  34. 'title' => __('Instagram URL', 'theme_admin'),
  35. ),
  36. 'email' => array(
  37. 'icon' => 'icon-envelope',
  38. 'title' => __('Email Address', 'theme_admin'),
  39. ),
  40. 'rss' => array(
  41. 'icon' => 'icon-rss',
  42. 'title' => __('RSS URL', 'theme_admin'),
  43. ),
  44. );
  45.  
  46. $widget_ops = array('classname' => 'widget_social', 'description' => __( 'Displays a list of Social Icon icons', 'theme_admin') );
  47. $this->WP_Widget('widget-social', THEME_NAME . ' - ' . __('Social', 'theme_admin'), $widget_ops);
  48. }
  49.  
  50. function widget( $args, $instance ) {
  51. extract( $args );
  52. $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
  53.  
  54. $output = '';
  55. if( !empty($instance['enable_sites']) ){
  56. foreach($instance['enable_sites'] as $key){
  57. $link = isset($instance[$key]) ? $instance[$key] : '#';
  58.  
  59. switch ($key) {
  60. case 'email':
  61. $output .= '<a href="mailto:' . $link . '" rel="nofollow" target="_blank"><i class="icon '.$this->sites[$key]['icon'].'"></i></a>';
  62. break;
  63.  
  64. default:
  65. $output .= '<a href="' . $link . '" rel="nofollow" target="_blank"><i class="icon '.$this->sites[$key]['icon'].'"></i></a>';
  66. break;
  67. }
  68. }
  69. }
  70.  
  71. echo $before_widget;
  72. if ( $title ) echo $before_title . $title . $after_title;
  73. echo $output;
  74. echo $after_widget;
  75. }
  76.  
  77. function update( $new_instance, $old_instance ) {
  78. $instance = $old_instance;
  79. $instance['title'] = strip_tags($new_instance['title']);
  80. $instance['enable_sites'] = $new_instance['enable_sites'];
  81.  
  82. if(!empty($instance['enable_sites'])){
  83. foreach($instance['enable_sites'] as $key){
  84. $instance[$key] = isset($new_instance[$key])?strip_tags($new_instance[$key]):'';
  85. }
  86. }
  87.  
  88. return $instance;
  89. }
  90.  
  91. function form( $instance ) {
  92. //Defaults
  93. $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
  94. $enable_sites = isset($instance['enable_sites']) ? $instance['enable_sites'] : array();
  95.  
  96. foreach($this->sites as $key => $value){
  97. $$key = isset($instance[$key]) ? esc_attr($instance[$key]) : '';
  98. }
  99.  
  100. ?>
  101. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'theme_admin'); ?>:</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 $title; ?>" /></p>
  102.  
  103. <p>
  104. <label for="<?php echo $this->get_field_id('enable_sites'); ?>"><?php _e( 'Enable Social Icon', 'theme_admin' ); ?>:</label>
  105. <select name="<?php echo $this->get_field_name('enable_sites'); ?>[]" style="height:10em" id="<?php echo $this->get_field_id('enable_sites'); ?>" class="social-icon-sites widefat" multiple="multiple">
  106. <?php foreach($this->sites as $key => $value):?>
  107. <option value="<?php echo $key;?>"<?php echo in_array($key, $enable_sites)? 'selected="selected"':'';?>><?php echo $value['title'];?></option>
  108. <?php endforeach;?>
  109. </select>
  110. </p>
  111.  
  112. <p>
  113. <em><?php _e("Note: Please input FULL URL <br/>(e.g. <code>http://www.example.com</code>)", 'theme_admin');?></em>
  114. </p>
  115.  
  116. <div class="social-icon-wrap">
  117. <?php foreach($this->sites as $key => $value):?>
  118. <p class="social-icon-config" id="social-icon-<?php echo $key;?>" <?php if(!in_array($key, $enable_sites)):?>style="display:none"<?php endif;?>>
  119. <label for="<?php echo $this->get_field_id( $key ); ?>"><?php echo $value['title']; ?>:</label>
  120. <input class="widefat" id="<?php echo $this->get_field_id( $key ); ?>" name="<?php echo $this->get_field_name( $key ); ?>" type="text" value="<?php echo $$key; ?>" />
  121. </p>
  122. <?php endforeach;?>
  123. </div>
  124.  
  125. <?php
  126. }
  127. }
  128. register_widget('Theme_Widget_Social');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement