PluginProbe
Maps Widget for Google Maps / 2.40
Maps Widget for Google Maps v2.40
1.86 1.90 1.92 1.93 1.95 2.0 2.01 2.05 2.06 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.51 2.60 2.65 2.66 2.70 2.75 2.80 All 129 releases
google-maps-widget / google-maps-widget.php

google-maps-widget.php in Maps Widget for Google Maps 2.40, at google-maps-widget.php

564 lines 23.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Google Maps Widget
4 Plugin URI: http://www.googlemapswidget.com/
5 Description: Display a single-image super-fast loading Google map in a widget. A larger, full featured map is available on click in a lightbox. Includes shortcode support and numerous options.
6 Author: Web factory Ltd
7 Version: 2.40
8 Author URI: http://www.webfactoryltd.com/
9 Text Domain: google-maps-widget
10 Domain Path: lang
11
12 Copyright 2012 - 2015 Web factory Ltd (email : gmw@webfactoryltd.com)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28
29 if (!defined('ABSPATH')) {
30 die();
31 }
32
33
34 define('GMW_OPTIONS', 'gmw_options');
35 define('GMW_CRON', 'gmw_cron');
36
37
38 require_once 'gmw-widget.php';
39 require_once 'gmw-tracking.php';
40
41
42 class GMW {
43 static $version = 2.40;
44
45 // hook everything up
46 static function init() {
47 GMW_tracking::init();
48
49 if (is_admin()) {
50 // check if minimal required WP version is used
51 self::check_wp_version(3.3);
52
53 // check some variables
54 self::upgrade();
55
56 // aditional links in plugin description
57 add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
58 array(__CLASS__, 'plugin_action_links'));
59 add_filter('plugin_row_meta', array(__CLASS__, 'plugin_meta_links'), 10, 2);
60
61 // enqueue admin scripts
62 add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts'));
63 add_action('customize_controls_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts'));
64
65 // JS dialog markup
66 add_action('admin_footer', array(__CLASS__, 'admin_dialogs_markup'));
67
68 // register AJAX endpoints
69 add_action('wp_ajax_gmw_subscribe', array(__CLASS__, 'email_subscribe'));
70 add_action('wp_ajax_gmw_activate', array(__CLASS__, 'activate_via_code'));
71
72 // handle dismiss button for all notices
73 add_action('admin_action_gmw_dismiss_notice', array(__CLASS__, 'dismiss_notice'));
74
75 // display various notices
76 self::add_notices();
77 } else {
78 // enqueue frontend scripts
79 add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));
80 add_action('wp_footer', array(__CLASS__, 'dialogs_markup'));
81 }
82
83 // add shortcode support
84 self::add_shortcode();
85 } // init
86
87
88 // some things have to be loaded earlier
89 static function plugins_loaded() {
90 load_plugin_textdomain('google-maps-widget', false, basename(dirname(__FILE__)) . '/lang');
91 add_filter('cron_schedules', array('GMW_tracking', 'register_cron_intervals'));
92 } // plugins_loaded
93
94
95 // initialize widgets
96 static function widgets_init() {
97 register_widget('GoogleMapsWidget');
98 } // widgets_init
99
100
101 // add widgets link to plugins page
102 static function plugin_action_links($links) {
103 $settings_link = '<a href="' . admin_url('widgets.php') . '" title="' . __('Configure Google Maps Widget', 'google-maps-widget') . '">' . __('Widgets', 'google-maps-widget') . '</a>';
104 array_unshift($links, $settings_link);
105
106 return $links;
107 } // plugin_action_links
108
109
110 // add links to plugin's description in plugins table
111 static function plugin_meta_links($links, $file) {
112 $documentation_link = '<a target="_blank" href="http://www.googlemapswidget.com/documentation/" title="' . __('View Google Maps Widget documentation', 'google-maps-widget') . '">'. __('Documentation', 'google-maps-widget') . '</a>';
113 $support_link = '<a target="_blank" href="http://wordpress.org/support/plugin/google-maps-widget" title="' . __('Problems? We are here to help!', 'google-maps-widget') . '">' . __('Support', 'google-maps-widget') . '</a>';
114 $review_link = '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/google-maps-widget" title="' . __('If you like it, please review the plugin', 'google-maps-widget') . '">' . __('Review the plugin', 'google-maps-widget') . '</a>';
115 $donate_link = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?business=gordan@webfactoryltd.com&cmd=_xclick&currency_code=USD&amount=&item_name=Google%20Maps%20Widget%20Donation" title="' . __('If you feel we deserve it, buy us coffee', 'google-maps-widget') . '">' . __('Donate', 'google-maps-widget') . '</a>';
116 $activate_link = '<a href="' . esc_url(admin_url('widgets.php?gmw_open_promo_dialog')) . '">' . __('Activate premium features for <b>FREE</b>', 'google-maps-widget') . '</a>';
117
118 if ($file == plugin_basename(__FILE__)) {
119 $links[] = $documentation_link;
120 $links[] = $support_link;
121 $links[] = $review_link;
122 $links[] = $donate_link;
123 if (!self::is_activated()) {
124 $links[] = $activate_link;
125 }
126 }
127
128 return $links;
129 } // plugin_meta_links
130
131
132 // check if user has the minimal WP version required by the plugin
133 static function check_wp_version($min_version) {
134 if (!version_compare(get_bloginfo('version'), $min_version, '>=')) {
135 add_action('admin_notices', array(__CLASS__, 'notice_min_version_error'));
136 }
137 } // check_wp_version
138
139
140 // display error message if WP version is too low
141 static function notice_min_version_error() {
142 echo '<div class="error"><p>' . sprintf(__('Google Maps Widget <b>requires WordPress version 3.3</b> or higher to function properly. You are using WordPress version %s. Please <a href="%s">update it</a>.', 'google-maps-widget'), get_bloginfo('version'), admin_url('update-core.php')) . '</p></div>';
143 } // notice_min_version_error
144
145
146 // print dialogs markup in footer
147 static function dialogs_markup() {
148 $out = '';
149 $widgets = GoogleMapsWidget::$widgets;
150
151 if (!$widgets) {
152 wp_dequeue_script('gmw');
153 wp_dequeue_script('gmw-fancybox');
154 return;
155 }
156
157 foreach ($widgets as $widget) {
158 if ($widget['bubble']) {
159 $iwloc = 'addr';
160 } else {
161 $iwloc = 'near';
162 }
163 if ($widget['ll']) {
164 $ll = '&amp;ll=' . $widget['ll'];
165 } else {
166 $ll = '';
167 }
168
169 $lang = substr(@$_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
170 if (!$lang) {
171 $lang = 'en';
172 }
173
174 $map_url = '//maps.google.com/maps?hl=' . $lang . '&amp;ie=utf8&amp;output=embed&amp;iwloc=' . $iwloc . '&amp;iwd=1&amp;mrt=loc&amp;t=' . $widget['type'] . '&amp;q=' . urlencode(remove_accents($widget['address'])) . '&amp;z=' . urlencode($widget['zoom']) . $ll;
175
176 $out .= '<div class="gmw-dialog" style="display: none;" data-map-height="' . $widget['height'] . '" data-map-width="' . $widget['width'] . '" data-map-skin="' . $widget['skin'] . '" data-map-iframe-url="' . $map_url . '" id="gmw-dialog-' . $widget['id'] . '" title="' . esc_attr($widget['title']) . '">';
177 if ($widget['header']) {
178 $out .= '<div class="gmw-header">' . wpautop(do_shortcode($widget['header'])) . '</div>';
179 }
180 $out .= '<div class="gmw-map"></div>';
181 if ($widget['footer']) {
182 $out .= '<div class="gmw-footer">' . wpautop(do_shortcode($widget['footer'])) . '</div>';
183 }
184 $out .= "</div>\n";
185 } // foreach $widgets
186
187 echo $out;
188 } // dialogs_markup
189
190
191 // check availability and register shortcode
192 static function add_shortcode() {
193 global $shortcode_tags;
194
195 if (isset($shortcode_tags['gmw'])) {
196 add_action('admin_notices', array(__CLASS__, 'notice_sc_conflict_error'));
197 } else {
198 add_shortcode('gmw', array(__CLASS__, 'do_shortcode'));
199 }
200 } // add_shortcode
201
202
203 // display notice if shortcode name is already taken
204 static function notice_sc_conflict_error() {
205 if (!self::is_activated()) {
206 return;
207 }
208
209 echo '<div class="error"><p><strong>' . __('Google Maps Widget shortcode is not active!', 'google-maps-widget') . '</strong>' . __(' Shortcode <i>[gmw]</i> is already in use by another plugin or theme. Please deactivate that theme or plugin.', 'google-maps-widget') . '</p></div>';
210 } // notice_sc_conflict_error
211
212
213 // handle dismiss button for all notices
214 // todo - convert all notices
215 static function dismiss_notice() {
216 $options = get_option(GMW_OPTIONS, array());
217
218 if (isset($_GET['notice']) && $_GET['notice'] == 'upgrade') {
219 $options['dismiss_notice_upgrade'] = true;
220 update_option(GMW_OPTIONS, $options);
221 }
222 if (isset($_GET['notice']) && $_GET['notice'] == 'rate') {
223 $options['dismiss_notice_rate'] = true;
224 update_option(GMW_OPTIONS, $options);
225 }
226
227 if ($_GET['redirect']) {
228 wp_redirect($_GET['redirect']);
229 } else {
230 wp_redirect(admin_url());
231 }
232 exit;
233 } // dismiss_notice
234
235
236 // maybe show some notices
237 static function add_notices() {
238 $options = get_option(GMW_OPTIONS, array());
239 $notice = false;
240
241 if ((!isset($options['dismiss_notice_upgrade']) || $options['dismiss_notice_upgrade'] == false) &&
242 !self::is_activated() &&
243 (GMW_tracking::count_active_widgets() > 0 || (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 3))) {
244 add_action('admin_notices', array(__CLASS__, 'notice_activate_extra_features'));
245 $notice = true;
246 } // show upgrade notice
247
248 if (!$notice &&
249 (!isset($options['dismiss_notice_rate']) || $options['dismiss_notice_rate'] == false) &&
250 GMW_tracking::count_active_widgets() > 0 &&
251 (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 30)) {
252 add_action('admin_notices', array(__CLASS__, 'notice_rate_plugin'));
253 } // show rate notice
254 } // add_notices
255
256
257 // display message to get extra features for GMW
258 static function notice_activate_extra_features() {
259 $activate_url = admin_url('widgets.php?gmw_open_promo_dialog');
260 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'upgrade', 'redirect' => $_SERVER['REQUEST_URI']), admin_url('admin.php'));
261
262 // todo detect WP version and add support for "is-dismissible"
263 // todo remove style from HTML
264 echo '<div id="gmw_activate_notice" class="updated notice"><p>' . __('<b>Google Maps Widget</b> has extra premium features you can get for <b style="color: #d54e21;">FREE</b>. This is a limited time offer so act now!', 'google-maps-widget');
265
266 echo '<br /><a href="' . esc_url($activate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Activate premium features for <b>FREE</b>', 'google-maps-widget') . '</a>';
267 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>';
268 echo '</p></div>';
269 } // notice_activate_extra_features
270
271
272 // display message to get extra features for GMW
273 static function notice_rate_plugin() {
274 $rate_url = 'https://wordpress.org/support/view/plugin-reviews/google-maps-widget?rate=5#postform';
275 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'rate', 'redirect' => $_SERVER['REQUEST_URI']), admin_url('admin.php'));
276
277 // todo detect WP version and add support for "is-dismissible"
278 // todo remove style from HTML
279 echo '<div id="gmw_rate_notice" class="updated notice"><p>' . __('Hi! We saw you\'ve been using <b>Google Maps Widget</b> for some time and wanted to ask for your help to make the plugin even better.<br>We don\'t need money :), just a minute of your time to rate the plugin. Thank you!', 'google-maps-widget');
280
281 echo '<br /><a target="_blank" href="' . esc_url($rate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Help us out &amp; rate the plugin', 'google-maps-widget') . '</a>';
282 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>';
283 echo '</p></div>';
284 } // notice_rate_plugin
285
286
287 // enqueue frontend scripts if necessary
288 static function enqueue_scripts() {
289 if (is_active_widget(false, false, 'googlemapswidget', true)) {
290 wp_enqueue_style('gmw', plugins_url('/css/gmw.css', __FILE__), array(), GMW::$version);
291 wp_enqueue_script('gmw-colorbox', plugins_url('/js/jquery.colorbox.min.js', __FILE__), array('jquery'), GMW::$version, true);
292 wp_enqueue_script('gmw', plugins_url('/js/gmw.js', __FILE__), array('jquery'), GMW::$version, true);
293 }
294 } // enqueue_scripts
295
296
297 // enqueue CSS and JS scripts on widgets page
298 static function admin_enqueue_scripts() {
299 global $wp_customize;
300
301 if (self::is_plugin_admin_page() || isset($wp_customize)) {
302 wp_enqueue_script('jquery-ui-tabs');
303 wp_enqueue_script('jquery-ui-dialog');
304 wp_enqueue_script('gmw-cookie', plugins_url('js/jquery.cookie.js', __FILE__), array('jquery'), GMW::$version, true);
305 wp_enqueue_script('gmw-admin', plugins_url('js/gmw-admin.js', __FILE__), array('jquery'), GMW::$version, true);
306
307 wp_enqueue_style('wp-jquery-ui-dialog');
308 wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW::$version);
309
310 $js_localize = array('subscribe_ok' => __('Check your inbox. Email with activation code is on its way.', 'google-maps-widget'),
311 'subscribe_duplicate' => __('You are already subscribed to our list. One activation code is valid for all sites so just use the code you already have.', 'google-maps-widget'),
312 'subscribe_error' => __('Something is not right on our end. Sorry :( Try again later.', 'google-maps-widget'),
313 'activate_ok' => __('Superb! Extra features are active ;)', 'google-maps-widget'),
314 'dialog_title' => __('GOOGLE MAPS WIDGET - Activate Extra Features', 'google-maps-widget'),
315 'undocumented_error' => __('An undocumented error has occured. Please refresh the page and try again.', 'google-maps-widget'),
316 'id_base' => 'googlemapswidget');
317 wp_localize_script('gmw-admin', 'gmw', $js_localize);
318 } // if
319 } // admin_enqueue_scripts
320
321
322 // check if plugin's admin page is shown
323 static function is_plugin_admin_page() {
324 $current_screen = get_current_screen();
325
326 if ($current_screen->id == 'widgets') {
327 return true;
328 } else {
329 return false;
330 }
331 } // is_plugin_admin_page
332
333
334 // check if activate-by-subscribing features have been activated
335 static function is_activated() {
336 $options = get_option(GMW_OPTIONS);
337
338 if (isset($options['activated']) && $options['activated'] === true) {
339 return true;
340 } else {
341 return false;
342 }
343 } // is_activated
344
345
346 // echo markup for promo dialog; only on widgets page
347 static function admin_dialogs_markup() {
348 if (!self::is_plugin_admin_page()) {
349 return false;
350 }
351
352 $current_user = wp_get_current_user();
353 if (empty($current_user->user_firstname)) {
354 $name = $current_user->display_name;
355 } else {
356 $name = $current_user->user_firstname;
357 }
358
359 $out = '<div id="gmw_promo_dialog">';
360 $out .= '<div id="gmw_dialog_subscribe"><div class="content"><h3 class="center">' . __('Fill out the form and<br>get extra features &amp; options <b>for FREE</b> instantly!', 'google-maps-widget') . '</h3>';
361 $out .= '<p class="input_row"><input value="' . $name . '" type="text" id="gmw_name" name="gmw_name" placeholder="Your name"><span class="error name" style="display: none;">Please enter your name.</span></p>';
362 $out .= '<p class="input_row"><input value="' . $current_user->user_email . '" type="text" name="gmw_email" id="gmw_email" placeholder="Your email address"><span style="display: none;" class="error email">Please double check your email address.</span></p>';
363 $out .= '<p class="center"><a id="gmw_subscribe" href="#" class="button button-primary big-button">Activate extra features</a><br><a href="#" class="" id="gmw_already_subscribed">I already have an activation code</a></p></div>';
364 $out .= '<div class="footer"><p><b>Why subscribe?</b></p><ul><li>We\'ll never share your email address</li><li>We won\'t spam you or overwhelm with emails</li><li>Be the first to get notified about new features</li><li>You\'ll get all future upgrades for free as well</li><li>You\'ll get discounts for our premium WP plugins</li></ul></div>';
365 $out .= '</div>'; // dialog subscribe
366 $out .= '<div id="gmw_dialog_activate"><div class="content"><h3 class="center">' . __('Enter your code and activate extra features', 'google-maps-widget') . '</h3>';
367 $out .= '<p class="input_row"><input type="text" id="gmw_code" name="gmw_code" placeholder="Your activation code"><span style="display: none;" class="error gmw_code">Please double check the activation code.</span></p><p class="center"><a href="#" class="button button-primary big-button" id="gmw_activate">Activate extra features</a></p></div>';
368 $out .= '<div class="footer"><p><b>FAQ</b></p><ul><li>Already subscribed? Enter your activation code above.</li><li>Didn\'t receive the email? Check your SPAM folder.</li><li>Lost your code or having other problems? <a href="mailto:gmw@webfactoryltd.com?subject=Lost%20activation%20code">Email us</a>.</li><li>Code is valid for an unlimited number of plugin installations.</li></ul></div>';
369 $out .= '</div>'; // activate screen
370 $out .= '</div>'; // dialog
371
372 echo $out;
373 } // admin_dialogs_markup
374
375
376 // send user's email to MailChimp via our server
377 static function email_subscribe() {
378 $name = trim($_POST['name']);
379 $email = trim($_POST['email']);
380 if (defined('WPLANG')) {
381 $lang = strtolower(substr(WPLANG, 0, 2));
382 } else {
383 $lang = 'en';
384 }
385
386 $res = wp_remote_post('http://www.googlemapswidget.com/subscribe.php', array('body' => array('name' => $name, 'email' => $email, 'lang' => $lang, 'ip' => $_SERVER['REMOTE_ADDR'], 'site' => get_home_url())));
387
388 // something's wrong with our server
389 if ($res['response']['code'] != 200 || is_wp_error($res)) {
390 wp_send_json_error('unknown');
391 }
392
393 if ($res['body'] == 'ok') {
394 wp_send_json_success();
395 } elseif ($res['body'] == 'duplicate') {
396 wp_send_json_error('duplicate');
397 } else {
398 wp_send_json_error('unknown');
399 }
400 } // email_subscribe
401
402
403 // check activation code and save if valid
404 static function activate_via_code() {
405 $code = trim($_POST['code']);
406
407 if (self::validate_activation_code($code)) {
408 $options = get_option(GMW_OPTIONS);
409 $options['activation_code'] = $code;
410 $options['activated'] = true;
411 update_option(GMW_OPTIONS, $options);
412
413 wp_send_json_success();
414 } else {
415 wp_send_json_error();
416 }
417 } // email_activate
418
419
420 // check if activation code for additional features is valid
421 static function validate_activation_code($code) {
422 if (strlen($code) == 6 && ($code[0] + $code[5]) == 9) {
423 return true;
424 } else {
425 return false;
426 }
427 } // validate_activation_code
428
429
430 // helper function for creating dropdowns
431 static function create_select_options($options, $selected = null, $output = true) {
432 $out = "\n";
433
434 foreach ($options as $tmp) {
435 if ($selected == $tmp['val']) {
436 $out .= "<option selected=\"selected\" value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option>\n";
437 } else {
438 $out .= "<option value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option>\n";
439 }
440 } // foreach
441
442 if ($output) {
443 echo $out;
444 } else {
445 return $out;
446 }
447 } // create_select_options
448
449
450 // fetch coordinates based on the address
451 static function get_coordinates($address, $force_refresh = false) {
452 $address_hash = md5('gmw' . $address);
453
454 if ($force_refresh || ($coordinates = get_transient($address_hash)) === false) {
455 $url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode($address) . '&sensor=false';
456 $result = wp_remote_get($url);
457
458 if (!is_wp_error($result) && $result['response']['code'] == 200) {
459 $data = new SimpleXMLElement($result['body']);
460
461 if ($data->status == 'OK') {
462 $cache_value['lat'] = (string) $data->result->geometry->location->lat;
463 $cache_value['lng'] = (string) $data->result->geometry->location->lng;
464 $cache_value['address'] = (string) $data->result->formatted_address;
465
466 // cache coordinates for 3 months
467 set_transient($address_hash, $cache_value, 3600*24*30*3);
468 $data = $cache_value;
469 } elseif (!$data->status) {
470 return false;
471 } else {
472 return false;
473 }
474 } else {
475 return false;
476 }
477 } else {
478 // data is cached, get it
479 $data = get_transient($address_hash);
480 }
481
482 return $data;
483 } // get_coordinates
484
485
486 // shortcode support for any GMW instance
487 static function do_shortcode($atts, $content = null) {
488 if (!self::is_activated()) {
489 return;
490 }
491
492 global $wp_widget_factory;
493 $atts = shortcode_atts(array('id' => 0), $atts);
494 $id = (int) $atts['id'];
495 $widgets = get_option('widget_googlemapswidget');
496
497 if (!$id || !isset($widgets[$id]) || empty($widgets[$id])) {
498 echo '<span class="gmw-error">Google Maps Widget shortcode error - please double-check the widget ID.</span>';
499 } else {
500 $widget_args = $widgets[$id];
501 $widget_instance['widget_id'] = 'googlemapswidget-' . $id;
502 $widget_instance['widget_name'] = 'Google Maps Widget';
503
504 echo '<span class="gmw-shortcode-widget">';
505 the_widget('GoogleMapsWidget', $widget_args, $widget_instance);
506 echo '</span>';
507 }
508 } // do_shortcode
509
510
511 // activate doesn't get fired on upgrades so we have to compensate
512 public static function upgrade() {
513 $options = get_option(GMW_OPTIONS);
514
515 if (!isset($options['first_version']) || !isset($options['first_install'])) {
516 $options['first_version'] = GMW::$version;
517 $options['first_install'] = current_time('timestamp');
518 update_option(GMW_OPTIONS, $options);
519 }
520 } // upgrade
521
522
523 // write down a few things on plugin activation
524 // NO DATA is sent anywhere unless user explicitly agrees to it!
525 static function activate() {
526 $options = get_option(GMW_OPTIONS);
527
528 if (!isset($options['first_version']) || !isset($options['first_install'])) {
529 $options['first_version'] = GMW::$version;
530 $options['first_install'] = current_time('timestamp');
531 $options['last_tracking'] = false;
532 update_option(GMW_OPTIONS, $options);
533 }
534 } // activate
535
536
537 // clean up on deactivation
538 static function deactivate() {
539 $options = get_option(GMW_OPTIONS);
540
541 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
542 GMW_tracking::clear_cron();
543 }
544 } // deactivate
545
546
547 // clean up on uninstall / delete
548 static function uninstall() {
549 if (!defined('WP_UNINSTALL_PLUGIN')) {
550 return;
551 }
552
553 delete_option(GMW_OPTIONS);
554 } // uninstall
555 } // class GMW
556
557
558 // hook everything up
559 register_activation_hook(__FILE__, array('GMW', 'activate'));
560 register_deactivation_hook(__FILE__, array('GMW', 'deactivate'));
561 register_uninstall_hook(__FILE__, array('GMW', 'uninstall'));
562 add_action('init', array('GMW', 'init'));
563 add_action('plugins_loaded', array('GMW', 'plugins_loaded'));
564 add_action('widgets_init', array('GMW', 'widgets_init'));