PluginProbe
Maps Widget for Google Maps / 2.75
Maps Widget for Google Maps v2.75
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.75, at google-maps-widget.php

573 lines 23.9 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.75
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.75';
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 (empty($options['dismiss_notice_upgrade']) && !self::is_activated()) {
242 add_action('admin_notices', array(__CLASS__, 'notice_activate_extra_features'));
243 $notice = true;
244 } // show upgrade notice
245
246 if (!$notice && empty($options['dismiss_notice_rate']) &&
247 GMW_tracking::count_active_widgets() > 0 &&
248 (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 3)) {
249 add_action('admin_notices', array(__CLASS__, 'notice_rate_plugin'));
250 $notice = true;
251 } // show rate notice
252
253 if (!$notice && !isset($options['allow_tracking']) && ((current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 5))) {
254 add_action('admin_notices', array('GMW_tracking', 'tracking_notice'));
255 $notice = true;
256 } // show tracking notice
257 } // add_notices
258
259
260 // display message to get extra features for GMW
261 static function notice_activate_extra_features() {
262 $activate_url = admin_url('widgets.php?gmw_open_promo_dialog');
263 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'upgrade', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php'));
264
265 // todo detect WP version and add support for "is-dismissible"
266 // todo remove style from HTML
267 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');
268
269 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>';
270 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>';
271 echo '</p></div>';
272 } // notice_activate_extra_features
273
274
275 // display message to get extra features for GMW
276 static function notice_rate_plugin() {
277 $rate_url = 'https://wordpress.org/support/view/plugin-reviews/google-maps-widget?rate=5#postform';
278 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'rate', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php'));
279
280 // todo detect WP version and add support for "is-dismissible"
281 // todo remove style from HTML
282 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');
283
284 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>';
285 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>';
286 echo '</p></div>';
287 } // notice_rate_plugin
288
289
290 // enqueue frontend scripts if necessary
291 static function enqueue_scripts() {
292 if (is_active_widget(false, false, 'googlemapswidget', true)) {
293 wp_enqueue_style('gmw', plugins_url('/css/gmw.css', __FILE__), array(), GMW::$version);
294 wp_enqueue_script('gmw-colorbox', plugins_url('/js/jquery.colorbox.min.js', __FILE__), array('jquery'), GMW::$version, true);
295 wp_enqueue_script('gmw', plugins_url('/js/gmw.js', __FILE__), array('jquery'), GMW::$version, true);
296 }
297 } // enqueue_scripts
298
299
300 // enqueue CSS and JS scripts on widgets page
301 static function admin_enqueue_scripts() {
302 global $wp_customize;
303
304 if (self::is_plugin_admin_page() || isset($wp_customize)) {
305 wp_enqueue_script('jquery-ui-tabs');
306 wp_enqueue_script('jquery-ui-dialog');
307 wp_enqueue_script('gmw-cookie', plugins_url('js/jquery.cookie.js', __FILE__), array('jquery'), GMW::$version, true);
308 wp_enqueue_script('gmw-admin', plugins_url('js/gmw-admin.js', __FILE__), array('jquery'), GMW::$version, true);
309
310 wp_enqueue_style('wp-jquery-ui-dialog');
311 wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW::$version);
312
313 $js_localize = array('subscribe_ok' => __('Check your inbox. Email with activation code is on its way.', 'google-maps-widget'),
314 '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'),
315 'subscribe_error' => __('Something is not right on our end. Sorry :( Try again later.', 'google-maps-widget'),
316 'activate_ok' => __('Superb! Extra features are active ;)', 'google-maps-widget'),
317 'dialog_title' => __('GOOGLE MAPS WIDGET - Activate Extra Features', 'google-maps-widget'),
318 'undocumented_error' => __('An undocumented error has occured. Please refresh the page and try again.', 'google-maps-widget'),
319 'id_base' => 'googlemapswidget');
320 wp_localize_script('gmw-admin', 'gmw', $js_localize);
321 } // if
322 } // admin_enqueue_scripts
323
324
325 // check if plugin's admin page is shown
326 static function is_plugin_admin_page() {
327 $current_screen = get_current_screen();
328
329 if ($current_screen->id == 'widgets') {
330 return true;
331 } else {
332 return false;
333 }
334 } // is_plugin_admin_page
335
336
337 // check if activate-by-subscribing features have been activated
338 static function is_activated() {
339 $options = get_option(GMW_OPTIONS);
340
341 if (isset($options['activated']) && $options['activated'] === true) {
342 return true;
343 } else {
344 return false;
345 }
346 } // is_activated
347
348
349 // echo markup for promo dialog; only on widgets page
350 static function admin_dialogs_markup() {
351 if (!self::is_plugin_admin_page()) {
352 return false;
353 }
354
355 $current_user = wp_get_current_user();
356 if (empty($current_user->user_firstname)) {
357 $name = $current_user->display_name;
358 } else {
359 $name = $current_user->user_firstname;
360 }
361
362 $out = '<div id="gmw_promo_dialog">';
363 $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>';
364 $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>';
365 $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>';
366 $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>';
367 $out .= '<div class="footer"><p><b>Still not sure?</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 discounts for our premium WP plugins</li></ul></div>';
368 $out .= '</div>'; // dialog subscribe
369 $out .= '<div id="gmw_dialog_activate"><div class="content"><h3 class="center">' . __('Enter your code and activate extra features', 'google-maps-widget') . '</h3>';
370 $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>';
371 $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>Still not getting the email? Try a different email address.</li><li>Code is valid for an unlimited number of plugin installations.</li></ul></div>';
372 $out .= '</div>'; // activate screen
373 $out .= '</div>'; // dialog
374
375 echo $out;
376 } // admin_dialogs_markup
377
378
379 // send user's email to MailChimp via our server
380 static function email_subscribe() {
381 $name = trim($_POST['name']);
382 $email = trim($_POST['email']);
383 if (defined('WPLANG')) {
384 $lang = strtolower(substr(WPLANG, 0, 2));
385 } else {
386 $lang = 'en';
387 }
388
389 $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())));
390
391 // something's wrong with our server
392 if ($res['response']['code'] != 200 || is_wp_error($res)) {
393 wp_send_json_error('unknown');
394 }
395
396 if ($res['body'] == 'ok') {
397 wp_send_json_success();
398 } elseif ($res['body'] == 'duplicate') {
399 wp_send_json_error('duplicate');
400 } else {
401 wp_send_json_error('unknown');
402 }
403 } // email_subscribe
404
405
406 // check activation code and save if valid
407 static function activate_via_code() {
408 $code = trim($_POST['code']);
409
410 if (self::validate_activation_code($code)) {
411 $options = get_option(GMW_OPTIONS);
412 $options['activation_code'] = $code;
413 $options['activated'] = true;
414 update_option(GMW_OPTIONS, $options);
415
416 wp_send_json_success();
417 } else {
418 wp_send_json_error();
419 }
420 } // email_activate
421
422
423 // check if activation code for additional features is valid
424 static function validate_activation_code($code) {
425 if (strlen($code) == 6 && ($code[0] + $code[5]) == 9) {
426 return true;
427 } else {
428 return false;
429 }
430 } // validate_activation_code
431
432
433 // helper function for creating dropdowns
434 static function create_select_options($options, $selected = null, $output = true) {
435 $out = "\n";
436
437 foreach ($options as $tmp) {
438 if ($selected == $tmp['val']) {
439 $out .= "<option selected=\"selected\" value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option>\n";
440 } else {
441 $out .= "<option value=\"{$tmp['val']}\">{$tmp['label']}&nbsp;</option>\n";
442 }
443 } // foreach
444
445 if ($output) {
446 echo $out;
447 } else {
448 return $out;
449 }
450 } // create_select_options
451
452
453 // fetch coordinates based on the address
454 static function get_coordinates($address, $force_refresh = false) {
455 $address_hash = md5('gmw' . $address);
456
457 if ($force_refresh || ($coordinates = get_transient($address_hash)) === false) {
458 $url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode($address) . '&sensor=false';
459 $result = wp_remote_get($url);
460
461 if (!is_wp_error($result) && $result['response']['code'] == 200) {
462 $data = new SimpleXMLElement($result['body']);
463
464 if ($data->status == 'OK') {
465 $cache_value['lat'] = (string) $data->result->geometry->location->lat;
466 $cache_value['lng'] = (string) $data->result->geometry->location->lng;
467 $cache_value['address'] = (string) $data->result->formatted_address;
468
469 // cache coordinates for 3 months
470 set_transient($address_hash, $cache_value, 3600*24*30*3);
471 $data = $cache_value;
472 } elseif (!$data->status) {
473 return false;
474 } else {
475 return false;
476 }
477 } else {
478 return false;
479 }
480 } else {
481 // data is cached, get it
482 $data = get_transient($address_hash);
483 }
484
485 return $data;
486 } // get_coordinates
487
488
489 // shortcode support for any GMW instance
490 static function do_shortcode($atts, $content = null) {
491 if (!self::is_activated()) {
492 return '';
493 }
494
495 global $wp_widget_factory;
496 $out = '';
497 $atts = shortcode_atts(array('id' => 0), $atts);
498 $id = (int) $atts['id'];
499 $widgets = get_option('widget_googlemapswidget');
500
501 if (!$id || empty($widgets[$id])) {
502 $out .= '<span class="gmw-error">Google Maps Widget shortcode error - please double-check the widget ID.</span>';
503 } else {
504 $widget_args = $widgets[$id];
505 $widget_instance['widget_id'] = 'googlemapswidget-' . $id;
506 $widget_instance['widget_name'] = 'Google Maps Widget';
507
508 $out .= '<span class="gmw-shortcode-widget">';
509 ob_start();
510 the_widget('GoogleMapsWidget', $widget_args, $widget_instance);
511 $out .= ob_get_contents();
512 ob_end_clean();
513 $out .= '</span>';
514 }
515
516 return $out;
517 } // do_shortcode
518
519
520 // activate doesn't get fired on upgrades so we have to compensate
521 public static function upgrade() {
522 $options = get_option(GMW_OPTIONS);
523
524 if (!isset($options['first_version']) || !isset($options['first_install'])) {
525 $options['first_version'] = GMW::$version;
526 $options['first_install'] = current_time('timestamp');
527 update_option(GMW_OPTIONS, $options);
528 }
529 } // upgrade
530
531
532 // write down a few things on plugin activation
533 // NO DATA is sent anywhere unless user explicitly agrees to it!
534 static function activate() {
535 $options = get_option(GMW_OPTIONS);
536
537 if (!isset($options['first_version']) || !isset($options['first_install'])) {
538 $options['first_version'] = GMW::$version;
539 $options['first_install'] = current_time('timestamp');
540 $options['last_tracking'] = false;
541 update_option(GMW_OPTIONS, $options);
542 }
543 } // activate
544
545
546 // clean up on deactivation
547 static function deactivate() {
548 $options = get_option(GMW_OPTIONS);
549
550 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
551 GMW_tracking::clear_cron();
552 }
553 } // deactivate
554
555
556 // clean up on uninstall / delete
557 static function uninstall() {
558 if (!defined('WP_UNINSTALL_PLUGIN')) {
559 return;
560 }
561
562 delete_option(GMW_OPTIONS);
563 } // uninstall
564 } // class GMW
565
566
567 // hook everything up
568 register_activation_hook(__FILE__, array('GMW', 'activate'));
569 register_deactivation_hook(__FILE__, array('GMW', 'deactivate'));
570 register_uninstall_hook(__FILE__, array('GMW', 'uninstall'));
571 add_action('init', array('GMW', 'init'));
572 add_action('plugins_loaded', array('GMW', 'plugins_loaded'));
573 add_action('widgets_init', array('GMW', 'widgets_init'));