diff --git a/inc/roots-widgets.php b/inc/roots-widgets.php index 3a024b3..1b91b14 100644 --- a/inc/roots-widgets.php +++ b/inc/roots-widgets.php @@ -1,73 +1,136 @@ 'widget_roots_vcard', 'description' => __('Use this widget to add a vCard', 'roots')); + $this->WP_Widget('widget_roots_vcard', __('Roots: vCard', 'roots'), $widget_ops); + $this->alt_option_name = 'widget_roots_vcard'; - function roots_vcard() { - $widget_ops = array('description' => 'Display a vCard'); - parent::WP_Widget(false, __('Roots: vCard', 'roots'), $widget_ops); + add_action('save_post', array(&$this, 'flush_widget_cache')); + add_action('deleted_post', array(&$this, 'flush_widget_cache')); + add_action('switch_theme', array(&$this, 'flush_widget_cache')); } function widget($args, $instance) { - extract($args); - extract($instance); + $cache = wp_cache_get('widget_roots_vcard', 'widget'); + + if (!is_array($cache)) { + $cache = array(); + } + + if (!isset($args['widget_id'])) { + $args['widget_id'] = null; + } + + if (isset($cache[$args['widget_id']])) { + echo $cache[$args['widget_id']]; + return; + } + + ob_start(); + extract($args, EXTR_SKIP); + + $title = apply_filters('widget_title', empty($instance['title']) ? __('vCard', 'roots') : $instance['title'], $instance, $this->id_base); + if (!isset($instance['street_address'])) { $instance['street_address'] = ''; } + if (!isset($instance['locality'])) { $instance['locality'] = ''; } + if (!isset($instance['region'])) { $instance['region'] = ''; } + if (!isset($instance['postal_code'])) { $instance['postal_code'] = ''; } + if (!isset($instance['tel'])) { $instance['tel'] = ''; } + if (!isset($instance['email'])) { $instance['email'] = ''; } + echo $before_widget; if ($title) { - echo $before_title, $title, $after_title; + echo $before_title; + echo $title; + echo $after_title; } ?>
-
- ,
-
-
+
+ ,
+
+
- +1-
-
+ +1-
+
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
- - + +
+add_action('widgets_init', 'roots_widget_init'); + +?> \ No newline at end of file