Nessuna descrizione

widget.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. class Nextend_Social_Login_Widget extends WP_Widget {
  3. public static function register() {
  4. register_widget('Nextend_Social_Login_Widget');
  5. }
  6. public function __construct() {
  7. parent::__construct('nextend_social_login', sprintf(__('%s Buttons', 'nextend-facebook-connect'), 'Nextend Social Login'));
  8. }
  9. public function form($instance) {
  10. $instance = wp_parse_args((array)$instance, array('title' => ''));
  11. $title = $instance['title'];
  12. $style = isset($instance['style']) ? $instance['style'] : 'default';
  13. $align = isset($instance['align']) ? $instance['align'] : 'left';
  14. $loginButtons = isset($instance['login-buttons']) ? !!intval($instance['login-buttons']) : true;
  15. $linkButtons = isset($instance['link-buttons']) ? !!intval($instance['link-buttons']) : false;
  16. $unlinkButtons = isset($instance['unlink-buttons']) ? !!intval($instance['unlink-buttons']) : false;
  17. $isPRO = apply_filters('nsl-pro', false);
  18. ?>
  19. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?>
  20. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
  21. name="<?php echo $this->get_field_name('title'); ?>" type="text"
  22. value="<?php echo esc_attr($title); ?>"/></label></p>
  23. <?php if ($isPRO): ?>
  24. <p>
  25. <label for="<?php echo $this->get_field_id('style'); ?>"><?php _e('Button style:', 'nextend-facebook-connect'); ?></label><br>
  26. <input class="widefat" id="<?php echo $this->get_field_id('style_default'); ?>"
  27. name="<?php echo $this->get_field_name('style'); ?>" type="radio" value="default"
  28. <?php if ($style == 'default'): ?>checked<?php endif; ?>/>
  29. <label for="<?php echo $this->get_field_id('style_default'); ?>"><?php _e('Default', 'nextend-facebook-connect'); ?></label>
  30. <br>
  31. <input class="widefat" id="<?php echo $this->get_field_id('style_icon'); ?>"
  32. name="<?php echo $this->get_field_name('style'); ?>" type="radio" value="icon"
  33. <?php if ($style == 'icon'): ?>checked<?php endif; ?>/>
  34. <label for="<?php echo $this->get_field_id('style_icon'); ?>"><?php _e('Icon', 'nextend-facebook-connect'); ?></label>
  35. <br>
  36. </p>
  37. <?php endif; ?>
  38. <p>
  39. <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Button align:', 'nextend-facebook-connect'); ?></label><br>
  40. <input class="widefat" id="<?php echo $this->get_field_id('align_left'); ?>"
  41. name="<?php echo $this->get_field_name('align'); ?>" type="radio" value="left"
  42. <?php if ($align == 'left'): ?>checked<?php endif; ?>/>
  43. <label for="<?php echo $this->get_field_id('align_left'); ?>"><?php _e('Left', 'nextend-facebook-connect'); ?></label>
  44. <br>
  45. <input class="widefat" id="<?php echo $this->get_field_id('align_center'); ?>"
  46. name="<?php echo $this->get_field_name('align'); ?>" type="radio" value="center"
  47. <?php if ($align == 'center'): ?>checked<?php endif; ?>/>
  48. <label for="<?php echo $this->get_field_id('align_center'); ?>"><?php _e('Center', 'nextend-facebook-connect'); ?></label>
  49. <br>
  50. <input class="widefat" id="<?php echo $this->get_field_id('align_right'); ?>"
  51. name="<?php echo $this->get_field_name('align'); ?>" type="radio" value="right"
  52. <?php if ($align == 'right'): ?>checked<?php endif; ?>/>
  53. <label for="<?php echo $this->get_field_id('align_right'); ?>"><?php _e('Right', 'nextend-facebook-connect'); ?></label>
  54. <br>
  55. </p>
  56. <p>
  57. <input name="<?php echo $this->get_field_name('login-buttons'); ?>" type="hidden" value="0"/>
  58. <input id="<?php echo $this->get_field_id('login-buttons'); ?>"
  59. name="<?php echo $this->get_field_name('login-buttons'); ?>" type="checkbox" value="1"
  60. <?php if ($loginButtons): ?>checked<?php endif; ?>/>
  61. <label for="<?php echo $this->get_field_id('login-buttons'); ?>"><?php _e('Show login buttons', 'nextend-facebook-connect'); ?></label>
  62. </p>
  63. <p>
  64. <input name="<?php echo $this->get_field_name('link-buttons'); ?>" type="hidden" value="0"/>
  65. <input id="<?php echo $this->get_field_id('link-buttons'); ?>"
  66. name="<?php echo $this->get_field_name('link-buttons'); ?>" type="checkbox" value="1"
  67. <?php if ($linkButtons): ?>checked<?php endif; ?>/>
  68. <label for="<?php echo $this->get_field_id('link-buttons'); ?>"><?php _e('Show link buttons', 'nextend-facebook-connect'); ?></label>
  69. </p>
  70. <p>
  71. <input name="<?php echo $this->get_field_name('unlink-buttons'); ?>" type="hidden" value="0"/>
  72. <input id="<?php echo $this->get_field_id('unlink-buttons'); ?>"
  73. name="<?php echo $this->get_field_name('unlink-buttons'); ?>" type="checkbox" value="1"
  74. <?php if ($unlinkButtons): ?>checked<?php endif; ?>/>
  75. <label for="<?php echo $this->get_field_id('unlink-buttons'); ?>"><?php _e('Show unlink buttons', 'nextend-facebook-connect'); ?></label>
  76. </p>
  77. <?php
  78. }
  79. public function widget($args, $instance) {
  80. $title = !empty($instance['title']) ? $instance['title'] : '';
  81. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  82. $style = !empty($instance['style']) ? $instance['style'] : 'default';
  83. $align = !empty($instance['align']) ? $instance['align'] : 'left';
  84. $loginButtons = isset($instance['login-buttons']) ? intval($instance['login-buttons']) : 1;
  85. $linkButtons = isset($instance['link-buttons']) ? intval($instance['link-buttons']) : 0;
  86. $unlinkButtons = isset($instance['unlink-buttons']) ? intval($instance['unlink-buttons']) : 0;
  87. echo $args['before_widget'];
  88. if ($title) {
  89. echo $args['before_title'] . $title . $args['after_title'];
  90. }
  91. echo do_shortcode('[nextend_social_login style="' . $style . '" login="' . $loginButtons . '" link="' . $linkButtons . '" unlink="' . $unlinkButtons . '" align="' . $align . '"]');
  92. echo $args['after_widget'];
  93. }
  94. }
  95. add_action('widgets_init', 'Nextend_Social_Login_Widget::register');