Advertisement
Guest User

Untitled

a guest
May 4th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <?php
  2.  
  3. /* -------------------------------------------------------
  4. You can add your custom functions below
  5. -------------------------------------------------------- */
  6.  
  7. /*--------------------------------------------------------
  8. Custom VCard Widget
  9. --------------------------------------------------------*/
  10.  
  11.  
  12. class Custom_357_Vcard_Widget extends WP_Widget {
  13.  
  14. private $fields = array(
  15. 'title' => 'Title',
  16. 'street_address' => 'Street Address',
  17. 'locality' => 'City/Locality',
  18. 'region' => 'State/Region',
  19. 'postal_code' => 'Zipcode/Postal Code',
  20. 'tel' => 'Telephone',
  21. 'twitter' => 'Twitter',
  22. 'email' => 'Email'
  23. );
  24.  
  25. function __construct() {
  26. $widget_ops = array('description' => __('Use this widget to add a vCard', 'crum'));
  27.  
  28. $this->WP_Widget('c_vcard_widget', __('Custom: vCard', 'crum'), $widget_ops);
  29. $this->alt_option_name = 'c_vcard_widget';
  30.  
  31. add_action('save_post', array(&$this, 'flush_widget_cache'));
  32. add_action('deleted_post', array(&$this, 'flush_widget_cache'));
  33. add_action('switch_theme', array(&$this, 'flush_widget_cache'));
  34. }
  35.  
  36. function widget($args, $instance) {
  37. $cache = wp_cache_get('widget_roots_vcard', 'widget');
  38.  
  39. if (!is_array($cache)) {
  40. $cache = array();
  41. }
  42.  
  43. if (!isset($args['widget_id'])) {
  44. $args['widget_id'] = null;
  45. }
  46.  
  47. if (isset($cache[$args['widget_id']])) {
  48. echo $cache[$args['widget_id']];
  49. return;
  50. }
  51.  
  52. ob_start();
  53. extract($args, EXTR_SKIP);
  54.  
  55. $title = apply_filters('widget_title', empty($instance['title']) ? __('vCard', 'crum') : $instance['title'], $instance, $this->id_base);
  56.  
  57.  
  58. foreach($this->fields as $name => $label) {
  59. if (!isset($instance[$name])) { $instance[$name] = ''; }
  60. }
  61.  
  62. echo $before_widget;
  63.  
  64. if ($title) {
  65.  
  66. echo $before_title;
  67. echo $title;
  68. echo $after_title;
  69.  
  70. }
  71. ?>
  72. <div class="crum-worldcontacts-widget">
  73.  
  74. <p class="adress">
  75. <?php if($instance['street_address']) { ?><i class="crumicon-earth"></i> <span class="street-address"><?php echo $instance['street_address']; ?></span>,
  76. <?php } if($instance['postal_code']){ ?> <span class="postal-code"><?php echo $instance['postal_code']; ?></span>
  77. <?php } if($instance['locality']){ ?><span class="locality"> <?php echo $instance['locality']; ?></span>,
  78. <?php } if($instance['region']) { ?> <span class="region"><?php echo $instance['region']; ?></span> <?php } ?>
  79.  
  80. </p>
  81. <?php if($instance['tel']) { ?><p class="phone"><i class="crumicon-phone"></i> <?php echo $instance['tel']; ?></p>
  82. <?php } if($instance['email']) { ?><p class="mail"><i class="crumicon-mail"></i> <?php _e('E-Mail', 'crum'); ?>: <a class="email" href="mailto:<?php echo $instance['email']; ?>"><?php echo $instance['email']; ?></a></p> <?php } ?>
  83. <?php if ($instance['twitter']) { ?><p class="twitter"><i class="soc-twitter"></i> <?php _e('Twitter', 'crum'); ?>: <a class="fn org url" href="<?php echo $instance['twitter']; ?>"><?php echo $instance['twitter'];?></a></p> <?php } ?>
  84.  
  85. </div>
  86.  
  87. <?php
  88. echo $after_widget;
  89.  
  90. $cache[$args['widget_id']] = ob_get_flush();
  91. wp_cache_set('widget_roots_vcard', $cache, 'widget');
  92. }
  93.  
  94. function update($new_instance, $old_instance) {
  95. $instance = array_map('strip_tags', $new_instance);
  96.  
  97. $this->flush_widget_cache();
  98.  
  99. $alloptions = wp_cache_get('alloptions', 'options');
  100.  
  101. if (isset($alloptions['widget_roots_vcard'])) {
  102. delete_option('widget_roots_vcard');
  103. }
  104.  
  105. return $instance;
  106. }
  107.  
  108. function flush_widget_cache() {
  109. wp_cache_delete('widget_roots_vcard', 'widget');
  110. }
  111.  
  112. function form($instance) {
  113. foreach($this->fields as $name => $label) {
  114. ${$name} = isset($instance[$name]) ? esc_attr($instance[$name]) : '';
  115. ?>
  116. <p>
  117. <label for="<?php echo esc_attr($this->get_field_id($name)); ?>"><?php _e("{$label}:", 'crum'); ?></label>
  118. <input class="widefat" id="<?php echo esc_attr($this->get_field_id($name)); ?>" name="<?php echo esc_attr($this->get_field_name($name)); ?>" type="text" value="<?php echo ${$name}; ?>">
  119. </p>
  120.  
  121.  
  122. <?php
  123. }
  124. }
  125. }
  126.  
  127. function Custom_357_Vcard_Widget_init() {
  128. register_widget('Custom_357_Vcard_Widget');
  129. }
  130.  
  131. add_action('widgets_init', 'Custom_357_Vcard_Widget_init');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement