social-widget.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // Flickr widget for hemingway WordPress theme
  3. class LCM_Social_Media_Widget extends WP_Widget{
  4. private $networks;
  5. function __construct() {
  6. parent::__construct(
  7. 'LCM_Social_Media_Widget',
  8. __('LCM social Media', 'hemingway'),
  9. array(
  10. 'description' => __( 'Connect your social media!', 'hemingway' )
  11. )
  12. );
  13. $this->networks = apply_filters('LCM_Social_Media_Widget', array(
  14. 'facebook' => __('Facebook', 'vantage'),
  15. 'twitter' => __('Twitter', 'vantage'),
  16. 'google-plus' => __('Google Plus', 'vantage'),
  17. 'github' => __('GitHub','vantage'),
  18. 'rss' => __('RSS', 'vantage'),
  19. ));
  20. }
  21. public function widget( $args, $instance ) {
  22. // outputs the content of the widget
  23. echo $args['before_widget'];
  24. if(!empty($instance['title'])) {
  25. echo $args['before_title'].$instance['title'].$args['after_title'];
  26. }
  27. foreach($this->networks as $id => $name) {
  28. if(!empty($instance[$id])) {
  29. ?><a class="social-media-icon social-media-icon-<?php echo $id ?> social-media-icon-<?php echo esc_attr($instance['size']) ?>" href="<?php echo esc_url( $instance[$id], array('http', 'https', 'mailto', 'skype') ) ?>" title="<?php echo esc_html( get_bloginfo('name') . ' ' . $name ) ?>" <?php if(!empty($instance['new_window'])) echo 'target="_blank"'; ?>><?php
  30. $icon = apply_filters('social_widget_icon_'.$id, '');
  31. if(!empty($icon)) echo $icon;
  32. else echo '<span class="fa fa-' . $id . '"></span>';
  33. ?></a><?php
  34. }
  35. }
  36. echo $args['after_widget'];
  37. }
  38. public function form( $instance ) {
  39. $instance = wp_parse_args($instance, array(
  40. 'size' => 'medium',
  41. 'title' => '',
  42. 'new_window' => false,
  43. ) );
  44. $sizes = apply_filters('vantage_social_widget_sizes', array(
  45. 'medium' => __('Medium', 'vantage'),
  46. ));
  47. ?>
  48. <p>
  49. <label for="<?php echo $this->get_field_id('title') ?>"><?php _e('Title', 'vantage') ?></label><br/>
  50. <input type="text" name="<?php echo $this->get_field_name('title') ?>" id="<?php echo $this->get_field_id('title') ?>" value="<?php echo esc_attr($instance['title']) ?>" />
  51. </p>
  52. <p>
  53. <label for="<?php echo $this->get_field_id('size') ?>"><?php _e('Icon Size', 'vantage') ?></label><br/>
  54. <select id="<?php echo $this->get_field_id('size') ?>" name="<?php echo $this->get_field_name('size') ?>">
  55. <?php foreach($sizes as $id => $name) : ?>
  56. <option value="<?php echo esc_attr($id) ?>" <?php selected($instance['size'], $id) ?>><?php echo esc_html($name) ?></option>
  57. <?php endforeach; ?>
  58. </select>
  59. </p>
  60. <?php
  61. foreach($this->networks as $id => $name) {
  62. ?>
  63. <p>
  64. <label for="<?php echo $this->get_field_id($id) ?>"><?php echo $name ?></label>
  65. <input type="text" id="<?php echo $this->get_field_id($id) ?>" name="<?php echo $this->get_field_name($id) ?>" value="<?php echo esc_attr(!empty($instance[$id]) ? $instance[$id] : '') ?>" class="widefat"/>
  66. </p>
  67. <?php
  68. }
  69. ?>
  70. <p>
  71. <input type="checkbox" name="<?php echo $this->get_field_name('new_window') ?>" id="<?php echo $this->get_field_id('new_window') ?>" <?php checked($instance['new_window']) ?> />
  72. <label for="<?php echo $this->get_field_id('new_window') ?>"><?php _e('Open in New Window', 'vantage') ?></label>
  73. </p>
  74. <?php
  75. }
  76. public function update( $new_instance, $old_instance ) {
  77. $new_instance['new_window'] = !empty($new_instance['new_window']);
  78. return $new_instance;
  79. }
  80. }
  81. register_widget('LCM_Social_Media_Widget'); ?>