Cookie Consent - Version 2.3.8

Version Description

  • Updated: tracking class
Download this release

Release Info

Developer Catapult_Themes
Plugin Icon 128x128 Cookie Consent
Version 2.3.8
Comparing to
See all releases

Code changes from version 2.3.7 to 2.3.8

readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Catapult_Themes, husobj, jraczynski
3
  Donate Link: https://www.paypal.me/catapultthemes
4
  Tags: cookie law, cookies, eu cookie law, eu privacy directive, cookie compliance, cookie law, cookie notice, cookie notification, wpml, geo ip
5
  Requires at least: 4.3
6
- Tested up to: 4.9.1
7
- Stable tag: 2.3.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  The only cookie consent plugin you'll ever need.
@@ -71,6 +71,9 @@ You will find more details of the regulations on the [Information Commissioner's
71
 
72
  == Changelog ==
73
 
 
 
 
74
  = 2.3.7 =
75
  * Updated: tracking class
76
 
@@ -252,4 +255,4 @@ You will find more details of the regulations on the [Information Commissioner's
252
  * Italian
253
 
254
  == Upgrade Notice ==
255
- Please note that the upgrade to version 2.x is significant. Although we've made every effort to ensure your settings are retained from previous versions, you may notice minor design differences to the notification bar.
3
  Donate Link: https://www.paypal.me/catapultthemes
4
  Tags: cookie law, cookies, eu cookie law, eu privacy directive, cookie compliance, cookie law, cookie notice, cookie notification, wpml, geo ip
5
  Requires at least: 4.3
6
+ Tested up to: 4.9.2
7
+ Stable tag: 2.3.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
  The only cookie consent plugin you'll ever need.
71
 
72
  == Changelog ==
73
 
74
+ = 2.3.8 =
75
+ * Updated: tracking class
76
+
77
  = 2.3.7 =
78
  * Updated: tracking class
79
 
255
  * Italian
256
 
257
  == Upgrade Notice ==
258
+ Please note that the upgrade to version 2.x is significant. Although we've made every effort to ensure your settings are retained from previous versions, you may notice minor design differences to the notification bar.
tracking/class-plugin-usage-tracker.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * This is the class that sends all the data back to the home site
4
  * It also handles opting in and deactivation
5
- * @version 1.1.2
6
  */
7
 
8
  // Exit if accessed directly
@@ -10,12 +10,11 @@ if ( ! defined( 'ABSPATH' ) ) {
10
  exit;
11
  }
12
 
13
-
14
  if( ! class_exists( 'Plugin_Usage_Tracker') ) {
15
-
16
  class Plugin_Usage_Tracker {
17
-
18
- private $wisdom_version = '1.1.2';
19
  private $home_url = '';
20
  private $plugin_file = '';
21
  private $plugin_name = '';
@@ -24,7 +23,9 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
24
  private $include_goodbye_form = true;
25
  private $marketing = false;
26
  private $collect_email = false;
27
-
 
 
28
  /**
29
  * Class constructor
30
  *
@@ -38,7 +39,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
38
  * 1: Request permission same time as tracking opt-in
39
  * 2: Request permission after opt-in
40
  */
41
- public function __construct(
42
  $_plugin_file,
43
  $_home_url,
44
  $_options,
@@ -48,43 +49,64 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
48
 
49
  $this->plugin_file = $_plugin_file;
50
  $this->home_url = trailingslashit( $_home_url );
51
- $this->plugin_name = basename( $this->plugin_file, '.php' );
 
 
 
 
 
 
 
 
 
 
 
52
  $this->options = $_options;
53
  $this->require_optin = $_require_optin;
54
  $this->include_goodbye_form = $_include_goodbye_form;
55
  $this->marketing = $_marketing;
56
-
57
- // Schedule some tracking when activated
58
- register_activation_hook( $this->plugin_file, array( $this, 'schedule_tracking' ) );
59
- // Deactivation hook
60
- register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate_this_plugin' ) );
61
-
 
 
 
 
 
 
 
 
62
  // Get it going
63
  $this->init();
64
-
65
  }
66
-
67
  public function init() {
68
  // Check marketing
69
  if( $this->marketing == 3 ) {
70
  $this->set_can_collect_email( true, $this->plugin_name );
71
  }
72
-
73
  // Check whether opt-in is required
74
  // If not, then tracking is allowed
75
  if( ! $this->require_optin ) {
76
  $this->set_can_collect_email( true, $this->plugin_name );
77
  $this->set_is_tracking_allowed( true );
78
  $this->update_block_notice();
79
- $this->do_tracking( true );
80
  }
81
 
82
- // Hook our do_tracking function to the daily action
 
 
83
  add_action( 'put_do_weekly_action', array( $this, 'do_tracking' ) );
84
 
85
  // Use this action for local testing
86
  // add_action( 'admin_init', array( $this, 'do_tracking' ) );
87
-
88
  // Display the admin notice on activation
89
  add_action( 'admin_notices', array( $this, 'optin_notice' ) );
90
  add_action( 'admin_notices', array( $this, 'marketing_notice' ) );
@@ -93,9 +115,9 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
93
  add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'filter_action_links' ) );
94
  add_action( 'admin_footer-plugins.php', array( $this, 'goodbye_ajax' ) );
95
  add_action( 'wp_ajax_goodbye_form', array( $this, 'goodbye_form_callback' ) );
96
-
97
  }
98
-
99
  /**
100
  * When the plugin is activated
101
  * Create scheduled event
@@ -104,12 +126,41 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
104
  * @since 1.0.0
105
  */
106
  public function schedule_tracking() {
107
- // For historical reasons, this is called 'weekly' but is in fact daily
108
  if ( ! wp_next_scheduled( 'put_do_weekly_action' ) ) {
109
- wp_schedule_event( time(), 'daily', 'put_do_weekly_action' );
 
110
  }
 
111
  }
112
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  /**
114
  * This is our function to get everything going
115
  * Check that user has opted in
@@ -120,25 +171,26 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
120
  * @param $force Force tracking if it's not time
121
  */
122
  public function do_tracking( $force=false ) {
 
123
  // If the home site hasn't been defined, we just drop out. Nothing much we can do.
124
  if ( ! $this->home_url ) {
125
  return;
126
  }
127
-
128
  // Check to see if the user has opted in to tracking
129
  $allow_tracking = $this->get_is_tracking_allowed();
130
  if( ! $allow_tracking ) {
131
  return;
132
  }
133
-
134
  // Check to see if it's time to track
135
  $track_time = $this->get_is_time_to_track();
136
  if( ! $track_time && ! $force ) {
137
  return;
138
  }
139
-
140
  $this->set_admin_email();
141
-
142
  // Get our data
143
  $body = $this->get_data();
144
 
@@ -146,7 +198,17 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
146
  $this->send_data( $body );
147
 
148
  }
149
-
 
 
 
 
 
 
 
 
 
 
150
  /**
151
  * Send the data to the home site
152
  *
@@ -154,7 +216,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
154
  */
155
  public function send_data( $body ) {
156
 
157
- $request = wp_remote_post(
158
  esc_url( $this->home_url . '?usage_tracker=hello' ),
159
  array(
160
  'method' => 'POST',
@@ -163,48 +225,49 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
163
  'httpversion' => '1.1',
164
  'blocking' => true,
165
  'body' => $body,
166
- 'user-agent' => 'PUT/1.0.0; ' . get_bloginfo( 'url' )
167
  )
168
  );
169
-
170
  $this->set_track_time();
171
-
172
  if( is_wp_error( $request ) ) {
173
  return $request;
174
  }
175
-
176
  }
177
-
178
  /**
179
  * Here we collect most of the data
180
- *
181
  * @since 1.0.0
182
  */
183
  public function get_data() {
184
-
185
  // Use this to pass error messages back if necessary
186
  $body['message'] = '';
187
-
188
  // Use this array to send data back
189
  $body = array(
190
- 'plugin_slug' => sanitize_text_field( $this->plugin_name ),
191
- 'url' => get_bloginfo( 'url' ),
192
- 'site_name' => get_bloginfo( 'name' ),
193
  'site_version' => get_bloginfo( 'version' ),
194
  'site_language' => get_bloginfo( 'language' ),
195
- 'charset' => get_bloginfo( 'charset' ),
196
  'wisdom_version' => $this->wisdom_version,
197
- 'php_version' => phpversion(),
198
- 'multisite' => is_multisite(),
199
- 'file_location' => __FILE__
 
200
  );
201
-
202
  // Collect the email if the correct option has been set
203
  if( $this->get_can_collect_email() ) {
204
  $body['email'] = $this->get_admin_email();
205
  }
206
  $body['marketing_method'] = $this->marketing;
207
-
208
  $body['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
209
 
210
  // Retrieve current plugin information
@@ -234,7 +297,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
234
  } else {
235
  $body['text_direction'] = 'not set';
236
  }
237
-
238
  /**
239
  * Get our plugin data
240
  * Currently we grab plugin name and version
@@ -242,10 +305,11 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
242
  * @since 1.0.0
243
  */
244
  $plugin = $this->plugin_data();
 
245
  if( empty( $plugin ) ) {
246
  // We can't find the plugin data
247
  // Send a message back to our home site
248
- $body['message'] .= __( 'We can\'t detect any plugin information. This is most probably because you have not included the code in the plugin main file.', 'plugin-usage-tracker' );
249
  $body['status'] = 'Data not found'; // Never translated
250
  } else {
251
  if( isset( $plugin['Name'] ) ) {
@@ -254,7 +318,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
254
  if( isset( $plugin['Version'] ) ) {
255
  $body['version'] = sanitize_text_field( $plugin['Version'] );
256
  }
257
- $body['status'] = 'Active'; // Never translated
258
  }
259
 
260
  /**
@@ -276,7 +340,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
276
  }
277
  $body['plugin_options'] = $this->options; // Returns array
278
  $body['plugin_options_fields'] = $plugin_options; // Returns object
279
-
280
  /**
281
  * Get our theme data
282
  * Currently we grab theme name and version
@@ -289,12 +353,15 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
289
  if( $theme->Version ) {
290
  $body['theme_version'] = sanitize_text_field( $theme->Version );
291
  }
 
 
 
292
 
293
  // Return the data
294
  return $body;
295
-
296
  }
297
-
298
  /**
299
  * Return plugin data
300
  * @since 1.0.0
@@ -315,14 +382,20 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
315
  */
316
  public function deactivate_this_plugin() {
317
  // Check to see if the user has opted in to tracking
318
- $allow_tracking = $this->get_is_tracking_allowed();
 
 
 
 
 
319
  if( ! $allow_tracking ) {
320
  return;
321
  }
 
322
  $body = $this->get_data();
323
  $body['status'] = 'Deactivated'; // Never translated
324
  $body['deactivated_date'] = time();
325
-
326
  // Add deactivation form data
327
  if( false !== get_option( 'wisdom_deactivation_reason_' . $this->plugin_name ) ) {
328
  $body['deactivation_reason'] = get_option( 'wisdom_deactivation_reason_' . $this->plugin_name );
@@ -330,31 +403,54 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
330
  if( false !== get_option( 'wisdom_deactivation_details_' . $this->plugin_name ) ) {
331
  $body['deactivation_details'] = get_option( 'wisdom_deactivation_details_' . $this->plugin_name );
332
  }
333
-
334
  $this->send_data( $body );
335
  // Clear scheduled update
336
  wp_clear_scheduled_hook( 'put_do_weekly_action' );
 
 
 
 
 
 
 
 
 
337
  }
338
-
339
  /**
340
  * Is tracking allowed?
341
  * @since 1.0.0
342
  */
343
  public function get_is_tracking_allowed() {
 
344
  // First, check if the user has changed their mind and opted out of tracking
345
  if( $this->has_user_opted_out() ) {
346
  $this->set_is_tracking_allowed( false, $this->plugin_name );
347
  return false;
348
  }
349
- // The wisdom_allow_tracking option is an array of plugins that are being tracked
350
- $allow_tracking = get_option( 'wisdom_allow_tracking' );
351
- // If this plugin is in the array, then tracking is allowed
352
- if( isset( $allow_tracking[$this->plugin_name] ) ) {
353
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
354
  }
 
355
  return false;
356
  }
357
-
358
  /**
359
  * Set if tracking is allowed
360
  * Option is an array of all plugins with tracking permitted
@@ -363,54 +459,86 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
363
  * @param $is_allowed Boolean true if tracking is allowed, false if not
364
  */
365
  public function set_is_tracking_allowed( $is_allowed, $plugin=null ) {
 
366
  if( empty( $plugin ) ) {
367
  $plugin = $this->plugin_name;
368
  }
 
369
  // The wisdom_allow_tracking option is an array of plugins that are being tracked
370
  $allow_tracking = get_option( 'wisdom_allow_tracking' );
371
-
372
  // If the user has decided to opt out
373
  if( $this->has_user_opted_out() ) {
374
- if( isset( $allow_tracking[$plugin] ) ) {
375
- unset( $allow_tracking[$plugin] );
 
 
 
 
376
  }
 
377
  } else if( $is_allowed || ! $this->require_optin ) {
378
  // If the user has agreed to allow tracking or if opt-in is not required
379
- if( empty( $allow_tracking ) || ! is_array( $allow_tracking ) ) {
380
- // If nothing exists in the option yet, start a new array with the plugin name
381
- $allow_tracking = array( $plugin => $plugin );
382
  } else {
383
- // Else add the plugin name to the array
384
- $allow_tracking[$plugin] = $plugin;
 
 
 
 
 
385
  }
 
386
  } else {
387
- if( isset( $allow_tracking[$plugin] ) ) {
388
- unset( $allow_tracking[$plugin] );
 
 
 
 
 
389
  }
 
390
  }
 
391
  update_option( 'wisdom_allow_tracking', $allow_tracking );
 
392
  }
393
-
394
  /**
395
  * Has the user opted out of allowing tracking?
 
396
  * @since 1.1.0
397
  * @return Boolean
398
  */
399
  public function has_user_opted_out() {
400
- // Iterate through the options that are being tracked looking for wisdom_opt_out setting
401
- if( ! empty( $this->options ) ) {
402
- foreach( $this->options as $option_name ) {
403
- // Check each option
404
- $options = get_option( $option_name );
405
- // If we find the setting, return true
406
- if( ! empty( $options['wisdom_opt_out'] ) ) {
407
- return true;
 
 
 
 
 
 
 
 
 
 
408
  }
409
  }
410
  }
411
  return false;
412
  }
413
-
414
  /**
415
  * Check if it's time to track
416
  * @since 1.1.1
@@ -422,14 +550,22 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
422
  // If we haven't set a time for this plugin yet, then we must track it
423
  return true;
424
  } else {
425
- // If the time is set, let's see if it's more than a day ago
426
- if( $track_times[$this->plugin_name] < strtotime( '-1 day' ) ) {
 
 
 
 
 
 
 
 
427
  return true;
428
  }
429
  }
430
  return false;
431
  }
432
-
433
  /**
434
  * Record the time we send tracking data
435
  * @since 1.1.1
@@ -441,7 +577,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
441
  $track_times[$this->plugin_name] = time();
442
  update_option( 'wisdom_last_track_time', $track_times );
443
  }
444
-
445
  /**
446
  * Set if we should block the opt-in notice for this plugin
447
  * Option is an array of all plugins that have received a response from the user
@@ -461,7 +597,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
461
  }
462
  update_option( 'wisdom_block_notice', $block_notice );
463
  }
464
-
465
  /**
466
  * Can we collect the email address?
467
  * @since 1.0.0
@@ -475,7 +611,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
475
  }
476
  return false;
477
  }
478
-
479
  /**
480
  * Set if user has allowed us to collect their email address
481
  * Option is an array of all plugins with email collection permitted
@@ -505,7 +641,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
505
  }
506
  update_option( 'wisdom_collect_email', $collect_email );
507
  }
508
-
509
  /**
510
  * Get the correct email address to use
511
  * @since 1.1.2
@@ -520,7 +656,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
520
  }
521
  return false;
522
  }
523
-
524
  /**
525
  * Set the correct email address to use
526
  * There might be more than one admin on the site
@@ -552,7 +688,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
552
  }
553
  update_option( 'wisdom_admin_emails', $admin_emails );
554
  }
555
-
556
  /**
557
  * Display the admin notice to users to allow them to opt in
558
  *
@@ -565,16 +701,18 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
565
  $action = sanitize_text_field( $_GET['plugin_action'] );
566
  if( $action == 'yes' ) {
567
  $this->set_is_tracking_allowed( true, $plugin );
568
- $this->do_tracking( true ); // Run this straightaway
 
569
  } else {
570
  $this->set_is_tracking_allowed( false, $plugin );
571
  }
572
  $this->update_block_notice( $plugin );
573
  }
574
-
575
  // Check whether to block the notice, e.g. because we're in a local environment
576
  // wisdom_block_notice works the same as wisdom_allow_tracking, an array of plugin names
577
  $block_notice = get_option( 'wisdom_block_notice' );
 
578
  if( isset( $block_notice[$this->plugin_name] ) ) {
579
  return;
580
  }
@@ -588,18 +726,18 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
588
  if ( stristr( network_site_url( '/' ), 'dev' ) !== false || stristr( network_site_url( '/' ), 'localhost' ) !== false || stristr( network_site_url( '/' ), ':8888' ) !== false ) {
589
  $this->update_block_notice();
590
  } else {
591
-
592
  // Display the notice requesting permission to track
593
  // Retrieve current plugin information
594
  $plugin = $this->plugin_data();
595
  $plugin_name = $plugin['Name'];
596
-
597
  // Args to add to query if user opts in to tracking
598
  $yes_args = array(
599
  'plugin' => $this->plugin_name,
600
  'plugin_action' => 'yes'
601
  );
602
-
603
  // Decide how to request permission to collect email addresses
604
  if( $this->marketing == 1 ) {
605
  // Option 1 combines permissions to track and collect email
@@ -613,31 +751,37 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
613
  'plugin' => $this->plugin_name,
614
  'plugin_action' => 'no'
615
  ) );
616
-
617
  // Decide on notice text
618
  if( $this->marketing != 1 ) {
619
  // Standard notice text
620
- $notice_text = __( 'Thank you for installing our plugin. We would like to track its usage on your site. We don\'t record any sensitive data, only information regarding the WordPress environment and plugin settings, which we will use to help us make improvements to the plugin. Tracking is completely optional.', 'plugin-usage-tracker' );
 
 
 
621
  } else {
622
  // If we have option 1 for marketing, we include reference to sending product information here
623
- $notice_text = __( 'Thank you for installing our plugin. We\'d like your permission to track its usage on your site and subscribe you to our newsletter. We won\'t record any sensitive data, only information regarding the WordPress environment and plugin settings, which we will use to help us make improvements to the plugin. Tracking is completely optional.', 'plugin-usage-tracker' );
 
 
 
624
  }
625
  // And we allow you to filter the text anyway
626
  $notice_text = apply_filters( 'wisdom_notice_text_' . esc_attr( $this->plugin_name ), $notice_text ); ?>
627
-
628
  <div class="notice notice-info updated put-dismiss-notice">
629
  <p><?php echo '<strong>' . esc_html( $plugin_name ) . '</strong>'; ?></p>
630
  <p><?php echo esc_html( $notice_text ); ?></p>
631
  <p>
632
- <a href="<?php echo esc_url( $url_yes ); ?>" class="button-secondary"><?php _e( 'Allow', 'plugin-usage-tracker' ); ?></a>
633
- <a href="<?php echo esc_url( $url_no ); ?>" class="button-secondary"><?php _e( 'Do Not Allow', 'plugin-usage-tracker' ); ?></a>
634
  </p>
635
  </div>
636
  <?php
637
  }
638
-
639
  }
640
-
641
  /**
642
  * Display the marketing notice to users if enabled
643
  * Only displays after the user has opted in to tracking
@@ -665,21 +809,24 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
665
  'plugin' => $this->plugin_name,
666
  'marketing_optin' => 'no'
667
  ) );
668
-
669
- $marketing_text = __( 'Thank you for opting in to tracking. Would you like to receive occasional news about this plugin, including details of new features and special offers?', 'plugin-usage-tracker' );
 
 
 
670
  $marketing_text = apply_filters( 'wisdom_marketing_text_' . esc_attr( $this->plugin_name ), $marketing_text ); ?>
671
-
672
  <div class="notice notice-info updated put-dismiss-notice">
673
  <p><?php echo '<strong>' . esc_html( $plugin_name ) . '</strong>'; ?></p>
674
  <p><?php echo esc_html( $marketing_text ); ?></p>
675
  <p>
676
- <a href="<?php echo esc_url( $url_yes ); ?>" data-putnotice="yes" class="button-secondary"><?php _e( 'Yes Please', 'plugin-usage-tracker' ); ?></a>
677
- <a href="<?php echo esc_url( $url_no ); ?>" data-putnotice="no" class="button-secondary"><?php _e( 'No Thank You', 'plugin-usage-tracker' ); ?></a>
678
  </p>
679
  </div>
680
  <?php }
681
  }
682
-
683
  /**
684
  * Filter the deactivation link to allow us to present a form when the user deactivates the plugin
685
  * @since 1.0.0
@@ -697,7 +844,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
697
  }
698
  return $links;
699
  }
700
-
701
  /*
702
  * Form text strings
703
  * These are non-filterable and used as fallback in case filtered strings aren't set correctly
@@ -705,21 +852,21 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
705
  */
706
  public function form_default_text() {
707
  $form = array();
708
- $form['heading'] = __( 'Sorry to see you go', 'plugin-usage-tracker' );
709
- $form['body'] = __( 'Before you deactivate the plugin, would you quickly give us your reason for doing so?', 'plugin-usage-tracker' );
710
  $form['options'] = array(
711
- __( 'Set up is too difficult', 'plugin-usage-tracker' ),
712
- __( 'Lack of documentation', 'plugin-usage-tracker' ),
713
- __( 'Not the features I wanted', 'plugin-usage-tracker' ),
714
- __( 'Found a better plugin', 'plugin-usage-tracker' ),
715
- __( 'Installed by mistake', 'plugin-usage-tracker' ),
716
- __( 'Only required temporarily', 'plugin-usage-tracker' ),
717
- __( 'Didn\'t work', 'plugin-usage-tracker' )
718
  );
719
- $form['details'] = __( 'Details (optional)', 'plugin-usage-tracker' );
720
  return $form;
721
  }
722
-
723
  /**
724
  * Form text strings
725
  * These can be filtered
@@ -730,7 +877,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
730
  $form = $this->form_default_text();
731
  return apply_filters( 'wisdom_form_text_' . esc_attr( $this->plugin_name ), $form );
732
  }
733
-
734
  /**
735
  * Form text strings
736
  * These can be filtered
@@ -755,7 +902,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
755
  $html .= '</div><!-- .put-goodbye-options -->';
756
  }
757
  $html .= '</div><!-- .put-goodbye-form-body -->';
758
- $html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'plugin-usage-tracker' ) . '</p>';
759
  ?>
760
  <div class="put-goodbye-form-bg"></div>
761
  <style type="text/css">
@@ -815,7 +962,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
815
  var url = document.getElementById("put-goodbye-link-<?php echo esc_attr( $this->plugin_name ); ?>");
816
  $('body').toggleClass('put-form-active');
817
  $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?>").fadeIn();
818
- $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?>").html( '<?php echo $html; ?>' + '<div class="put-goodbye-form-footer"><p><a id="put-submit-form" class="button primary" href="#"><?php _e( 'Submit and Deactivate', 'plugin-usage-tracker' ); ?></a>&nbsp;<a class="secondary button" href="'+url+'"><?php _e( 'Just Deactivate', 'plugin-usage-tracker' ); ?></a></p></div>');
819
  $('#put-submit-form').on('click', function(e){
820
  // As soon as we click, the body of the form should disappear
821
  $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?> .put-goodbye-form-body").fadeOut();
@@ -853,7 +1000,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
853
  });
854
  </script>
855
  <?php }
856
-
857
  /**
858
  * AJAX callback when the form is submitted
859
  * @since 1.0.0
@@ -872,7 +1019,7 @@ if( ! class_exists( 'Plugin_Usage_Tracker') ) {
872
  echo 'success';
873
  wp_die();
874
  }
875
-
876
  }
877
-
878
- }
2
  /**
3
  * This is the class that sends all the data back to the home site
4
  * It also handles opting in and deactivation
5
+ * @version 1.2.3
6
  */
7
 
8
  // Exit if accessed directly
10
  exit;
11
  }
12
 
 
13
  if( ! class_exists( 'Plugin_Usage_Tracker') ) {
14
+
15
  class Plugin_Usage_Tracker {
16
+
17
+ private $wisdom_version = '1.2.3';
18
  private $home_url = '';
19
  private $plugin_file = '';
20
  private $plugin_name = '';
23
  private $include_goodbye_form = true;
24
  private $marketing = false;
25
  private $collect_email = false;
26
+ private $what_am_i = 'plugin';
27
+ private $theme_allows_tracking = 0;
28
+
29
  /**
30
  * Class constructor
31
  *
39
  * 1: Request permission same time as tracking opt-in
40
  * 2: Request permission after opt-in
41
  */
42
+ public function __construct(
43
  $_plugin_file,
44
  $_home_url,
45
  $_options,
49
 
50
  $this->plugin_file = $_plugin_file;
51
  $this->home_url = trailingslashit( $_home_url );
52
+
53
+ // If the filename is 'functions' then we're tracking a theme
54
+ if( basename( $this->plugin_file, '.php' ) != 'functions' ) {
55
+ $this->plugin_name = basename( $this->plugin_file, '.php' );
56
+ } else {
57
+ $this->what_am_i = 'theme';
58
+ $theme = wp_get_theme();
59
+ if( $theme->Name ) {
60
+ $this->plugin_name = sanitize_text_field( $theme->Name );
61
+ }
62
+ }
63
+
64
  $this->options = $_options;
65
  $this->require_optin = $_require_optin;
66
  $this->include_goodbye_form = $_include_goodbye_form;
67
  $this->marketing = $_marketing;
68
+
69
+ // Only use this on switching theme
70
+ $this->theme_allows_tracking = get_theme_mod( 'wisdom-allow-tracking', 0 );
71
+
72
+ // Schedule / deschedule tracking when activated / deactivated
73
+ if( $this->what_am_i == 'theme' ) {
74
+ // Need to think about scheduling for sites that have already activated the theme
75
+ add_action( 'after_switch_theme', array( $this, 'schedule_tracking' ) );
76
+ add_action( 'switch_theme', array( $this, 'deactivate_this_plugin' ) );
77
+ } else {
78
+ register_activation_hook( $this->plugin_file, array( $this, 'schedule_tracking' ) );
79
+ register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate_this_plugin' ) );
80
+ }
81
+
82
  // Get it going
83
  $this->init();
84
+
85
  }
86
+
87
  public function init() {
88
  // Check marketing
89
  if( $this->marketing == 3 ) {
90
  $this->set_can_collect_email( true, $this->plugin_name );
91
  }
92
+
93
  // Check whether opt-in is required
94
  // If not, then tracking is allowed
95
  if( ! $this->require_optin ) {
96
  $this->set_can_collect_email( true, $this->plugin_name );
97
  $this->set_is_tracking_allowed( true );
98
  $this->update_block_notice();
99
+ $this->do_tracking();
100
  }
101
 
102
+ // Hook our do_tracking function to the weekly action
103
+ add_filter( 'cron_schedules', array( $this, 'schedule_weekly_event' ) );
104
+ // It's called weekly, but in fact it could be daily, weekly or monthly
105
  add_action( 'put_do_weekly_action', array( $this, 'do_tracking' ) );
106
 
107
  // Use this action for local testing
108
  // add_action( 'admin_init', array( $this, 'do_tracking' ) );
109
+
110
  // Display the admin notice on activation
111
  add_action( 'admin_notices', array( $this, 'optin_notice' ) );
112
  add_action( 'admin_notices', array( $this, 'marketing_notice' ) );
115
  add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'filter_action_links' ) );
116
  add_action( 'admin_footer-plugins.php', array( $this, 'goodbye_ajax' ) );
117
  add_action( 'wp_ajax_goodbye_form', array( $this, 'goodbye_form_callback' ) );
118
+
119
  }
120
+
121
  /**
122
  * When the plugin is activated
123
  * Create scheduled event
126
  * @since 1.0.0
127
  */
128
  public function schedule_tracking() {
 
129
  if ( ! wp_next_scheduled( 'put_do_weekly_action' ) ) {
130
+ $schedule = $this->get_schedule();
131
+ wp_schedule_event( time(), $schedule, 'put_do_weekly_action' );
132
  }
133
+ $this->do_tracking( true );
134
  }
135
+
136
+ /**
137
+ * Create weekly schedule
138
+ *
139
+ * @since 1.2.3
140
+ */
141
+ public function schedule_weekly_event( $schedules ) {
142
+ $schedules['weekly'] = array(
143
+ 'interval' => 604800,
144
+ 'display' => __( 'Once Weekly' )
145
+ );
146
+ $schedules['monthly'] = array(
147
+ 'interval' => 2635200,
148
+ 'display' => __( 'Once Monthly' )
149
+ );
150
+ return $schedules;
151
+ }
152
+
153
+ /**
154
+ * Get how frequently data is tracked back
155
+ *
156
+ * @since 1.2.3
157
+ */
158
+ public function get_schedule() {
159
+ // Could be daily, weekly or monthly
160
+ $schedule = apply_filters( 'wisdom_filter_schedule', 'monthly' );
161
+ return $schedule;
162
+ }
163
+
164
  /**
165
  * This is our function to get everything going
166
  * Check that user has opted in
171
  * @param $force Force tracking if it's not time
172
  */
173
  public function do_tracking( $force=false ) {
174
+
175
  // If the home site hasn't been defined, we just drop out. Nothing much we can do.
176
  if ( ! $this->home_url ) {
177
  return;
178
  }
179
+
180
  // Check to see if the user has opted in to tracking
181
  $allow_tracking = $this->get_is_tracking_allowed();
182
  if( ! $allow_tracking ) {
183
  return;
184
  }
185
+
186
  // Check to see if it's time to track
187
  $track_time = $this->get_is_time_to_track();
188
  if( ! $track_time && ! $force ) {
189
  return;
190
  }
191
+
192
  $this->set_admin_email();
193
+
194
  // Get our data
195
  $body = $this->get_data();
196
 
198
  $this->send_data( $body );
199
 
200
  }
201
+
202
+ /**
203
+ * We hook this to admin_init when the user accepts tracking
204
+ * Ensures the email address is available
205
+ *
206
+ * @since 1.2.1
207
+ */
208
+ public function force_tracking() {
209
+ $this->do_tracking( true ); // Run this straightaway
210
+ }
211
+
212
  /**
213
  * Send the data to the home site
214
  *
216
  */
217
  public function send_data( $body ) {
218
 
219
+ $request = wp_remote_post(
220
  esc_url( $this->home_url . '?usage_tracker=hello' ),
221
  array(
222
  'method' => 'POST',
225
  'httpversion' => '1.1',
226
  'blocking' => true,
227
  'body' => $body,
228
+ 'user-agent' => 'PUT/1.0.0; ' . home_url()
229
  )
230
  );
231
+
232
  $this->set_track_time();
233
+
234
  if( is_wp_error( $request ) ) {
235
  return $request;
236
  }
237
+
238
  }
239
+
240
  /**
241
  * Here we collect most of the data
242
+ *
243
  * @since 1.0.0
244
  */
245
  public function get_data() {
246
+
247
  // Use this to pass error messages back if necessary
248
  $body['message'] = '';
249
+
250
  // Use this array to send data back
251
  $body = array(
252
+ 'plugin_slug' => sanitize_text_field( $this->plugin_name ),
253
+ 'url' => home_url(),
254
+ 'site_name' => get_bloginfo( 'name' ),
255
  'site_version' => get_bloginfo( 'version' ),
256
  'site_language' => get_bloginfo( 'language' ),
257
+ 'charset' => get_bloginfo( 'charset' ),
258
  'wisdom_version' => $this->wisdom_version,
259
+ 'php_version' => phpversion(),
260
+ 'multisite' => is_multisite(),
261
+ 'file_location' => __FILE__,
262
+ 'product_type' => esc_html( $this->what_am_i )
263
  );
264
+
265
  // Collect the email if the correct option has been set
266
  if( $this->get_can_collect_email() ) {
267
  $body['email'] = $this->get_admin_email();
268
  }
269
  $body['marketing_method'] = $this->marketing;
270
+
271
  $body['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
272
 
273
  // Retrieve current plugin information
297
  } else {
298
  $body['text_direction'] = 'not set';
299
  }
300
+
301
  /**
302
  * Get our plugin data
303
  * Currently we grab plugin name and version
305
  * @since 1.0.0
306
  */
307
  $plugin = $this->plugin_data();
308
+ $body['status'] = 'Active'; // Never translated
309
  if( empty( $plugin ) ) {
310
  // We can't find the plugin data
311
  // Send a message back to our home site
312
+ $body['message'] .= __( 'We can\'t detect any product information. This is most probably because you have not included the code snippet.', 'singularity' );
313
  $body['status'] = 'Data not found'; // Never translated
314
  } else {
315
  if( isset( $plugin['Name'] ) ) {
318
  if( isset( $plugin['Version'] ) ) {
319
  $body['version'] = sanitize_text_field( $plugin['Version'] );
320
  }
321
+
322
  }
323
 
324
  /**
340
  }
341
  $body['plugin_options'] = $this->options; // Returns array
342
  $body['plugin_options_fields'] = $plugin_options; // Returns object
343
+
344
  /**
345
  * Get our theme data
346
  * Currently we grab theme name and version
353
  if( $theme->Version ) {
354
  $body['theme_version'] = sanitize_text_field( $theme->Version );
355
  }
356
+ if( $theme->Template ) {
357
+ $body['theme_parent'] = sanitize_text_field( $theme->Template );
358
+ }
359
 
360
  // Return the data
361
  return $body;
362
+
363
  }
364
+
365
  /**
366
  * Return plugin data
367
  * @since 1.0.0
382
  */
383
  public function deactivate_this_plugin() {
384
  // Check to see if the user has opted in to tracking
385
+ if( $this->what_am_i == 'theme' ) {
386
+ $allow_tracking = $this->theme_allows_tracking;
387
+ } else {
388
+ $allow_tracking = $this->get_is_tracking_allowed();
389
+ }
390
+
391
  if( ! $allow_tracking ) {
392
  return;
393
  }
394
+
395
  $body = $this->get_data();
396
  $body['status'] = 'Deactivated'; // Never translated
397
  $body['deactivated_date'] = time();
398
+
399
  // Add deactivation form data
400
  if( false !== get_option( 'wisdom_deactivation_reason_' . $this->plugin_name ) ) {
401
  $body['deactivation_reason'] = get_option( 'wisdom_deactivation_reason_' . $this->plugin_name );
403
  if( false !== get_option( 'wisdom_deactivation_details_' . $this->plugin_name ) ) {
404
  $body['deactivation_details'] = get_option( 'wisdom_deactivation_details_' . $this->plugin_name );
405
  }
406
+
407
  $this->send_data( $body );
408
  // Clear scheduled update
409
  wp_clear_scheduled_hook( 'put_do_weekly_action' );
410
+
411
+ // Clear the wisdom_last_track_time value for this plugin
412
+ // @since 1.2.2
413
+ $track_time = get_option( 'wisdom_last_track_time' );
414
+ if( isset( $track_time[$this->plugin_name]) ) {
415
+ unset( $track_time[$this->plugin_name] );
416
+ }
417
+ update_option( 'wisdom_last_track_time', $track_time );
418
+
419
  }
420
+
421
  /**
422
  * Is tracking allowed?
423
  * @since 1.0.0
424
  */
425
  public function get_is_tracking_allowed() {
426
+
427
  // First, check if the user has changed their mind and opted out of tracking
428
  if( $this->has_user_opted_out() ) {
429
  $this->set_is_tracking_allowed( false, $this->plugin_name );
430
  return false;
431
  }
432
+
433
+ if( $this->what_am_i == 'theme' ) {
434
+
435
+ $mod = get_theme_mod( 'wisdom-allow-tracking', 0 );
436
+ if( $mod ) {
437
+ return true;
438
+ }
439
+
440
+ } else {
441
+
442
+ // The wisdom_allow_tracking option is an array of plugins that are being tracked
443
+ $allow_tracking = get_option( 'wisdom_allow_tracking' );
444
+ // If this plugin is in the array, then tracking is allowed
445
+ if( isset( $allow_tracking[$this->plugin_name] ) ) {
446
+ return true;
447
+ }
448
+
449
  }
450
+
451
  return false;
452
  }
453
+
454
  /**
455
  * Set if tracking is allowed
456
  * Option is an array of all plugins with tracking permitted
459
  * @param $is_allowed Boolean true if tracking is allowed, false if not
460
  */
461
  public function set_is_tracking_allowed( $is_allowed, $plugin=null ) {
462
+
463
  if( empty( $plugin ) ) {
464
  $plugin = $this->plugin_name;
465
  }
466
+
467
  // The wisdom_allow_tracking option is an array of plugins that are being tracked
468
  $allow_tracking = get_option( 'wisdom_allow_tracking' );
469
+
470
  // If the user has decided to opt out
471
  if( $this->has_user_opted_out() ) {
472
+ if( $this->what_am_i == 'theme' ) {
473
+ set_theme_mod( 'wisdom-allow-tracking', 0 );
474
+ } else {
475
+ if( isset( $allow_tracking[$plugin] ) ) {
476
+ unset( $allow_tracking[$plugin] );
477
+ }
478
  }
479
+
480
  } else if( $is_allowed || ! $this->require_optin ) {
481
  // If the user has agreed to allow tracking or if opt-in is not required
482
+
483
+ if( $this->what_am_i == 'theme' ) {
484
+ set_theme_mod( 'wisdom-allow-tracking', 1 );
485
  } else {
486
+ if( empty( $allow_tracking ) || ! is_array( $allow_tracking ) ) {
487
+ // If nothing exists in the option yet, start a new array with the plugin name
488
+ $allow_tracking = array( $plugin => $plugin );
489
+ } else {
490
+ // Else add the plugin name to the array
491
+ $allow_tracking[$plugin] = $plugin;
492
+ }
493
  }
494
+
495
  } else {
496
+
497
+ if( $this->what_am_i == 'theme' ) {
498
+ set_theme_mod( 'wisdom-allow-tracking', 0 );
499
+ } else {
500
+ if( isset( $allow_tracking[$plugin] ) ) {
501
+ unset( $allow_tracking[$plugin] );
502
+ }
503
  }
504
+
505
  }
506
+
507
  update_option( 'wisdom_allow_tracking', $allow_tracking );
508
+
509
  }
510
+
511
  /**
512
  * Has the user opted out of allowing tracking?
513
+ * Note that themes are opt in / plugins are opt out
514
  * @since 1.1.0
515
  * @return Boolean
516
  */
517
  public function has_user_opted_out() {
518
+ // Different opt-out methods for plugins and themes
519
+ if( $this->what_am_i == 'theme' ) {
520
+ // Look for the theme mod
521
+ $mod = get_theme_mod( 'wisdom-allow-tracking', 0 );
522
+ if( false === $mod ) {
523
+ // If the theme mod is not set, then return true - the user has opted out
524
+ return true;
525
+ }
526
+ } else {
527
+ // Iterate through the options that are being tracked looking for wisdom_opt_out setting
528
+ if( ! empty( $this->options ) ) {
529
+ foreach( $this->options as $option_name ) {
530
+ // Check each option
531
+ $options = get_option( $option_name );
532
+ // If we find the setting, return true
533
+ if( ! empty( $options['wisdom_opt_out'] ) ) {
534
+ return true;
535
+ }
536
  }
537
  }
538
  }
539
  return false;
540
  }
541
+
542
  /**
543
  * Check if it's time to track
544
  * @since 1.1.1
550
  // If we haven't set a time for this plugin yet, then we must track it
551
  return true;
552
  } else {
553
+ // If the time is set, let's get our schedule and check if it's time to track
554
+ $schedule = $this->get_schedule();
555
+ if( $schedule == 'daily' ) {
556
+ $period = 'day';
557
+ } else if( $schedule == 'weekly' ) {
558
+ $period = 'week';
559
+ } else {
560
+ $period = 'month';
561
+ }
562
+ if( $track_times[$this->plugin_name] < strtotime( '-1 ' . $period ) ) {
563
  return true;
564
  }
565
  }
566
  return false;
567
  }
568
+
569
  /**
570
  * Record the time we send tracking data
571
  * @since 1.1.1
577
  $track_times[$this->plugin_name] = time();
578
  update_option( 'wisdom_last_track_time', $track_times );
579
  }
580
+
581
  /**
582
  * Set if we should block the opt-in notice for this plugin
583
  * Option is an array of all plugins that have received a response from the user
597
  }
598
  update_option( 'wisdom_block_notice', $block_notice );
599
  }
600
+
601
  /**
602
  * Can we collect the email address?
603
  * @since 1.0.0
611
  }
612
  return false;
613
  }
614
+
615
  /**
616
  * Set if user has allowed us to collect their email address
617
  * Option is an array of all plugins with email collection permitted
641
  }
642
  update_option( 'wisdom_collect_email', $collect_email );
643
  }
644
+
645
  /**
646
  * Get the correct email address to use
647
  * @since 1.1.2
656
  }
657
  return false;
658
  }
659
+
660
  /**
661
  * Set the correct email address to use
662
  * There might be more than one admin on the site
688
  }
689
  update_option( 'wisdom_admin_emails', $admin_emails );
690
  }
691
+
692
  /**
693
  * Display the admin notice to users to allow them to opt in
694
  *
701
  $action = sanitize_text_field( $_GET['plugin_action'] );
702
  if( $action == 'yes' ) {
703
  $this->set_is_tracking_allowed( true, $plugin );
704
+ // Run this straightaway
705
+ add_action( 'admin_init', array( $this, 'force_tracking' ) );
706
  } else {
707
  $this->set_is_tracking_allowed( false, $plugin );
708
  }
709
  $this->update_block_notice( $plugin );
710
  }
711
+
712
  // Check whether to block the notice, e.g. because we're in a local environment
713
  // wisdom_block_notice works the same as wisdom_allow_tracking, an array of plugin names
714
  $block_notice = get_option( 'wisdom_block_notice' );
715
+
716
  if( isset( $block_notice[$this->plugin_name] ) ) {
717
  return;
718
  }
726
  if ( stristr( network_site_url( '/' ), 'dev' ) !== false || stristr( network_site_url( '/' ), 'localhost' ) !== false || stristr( network_site_url( '/' ), ':8888' ) !== false ) {
727
  $this->update_block_notice();
728
  } else {
729
+
730
  // Display the notice requesting permission to track
731
  // Retrieve current plugin information
732
  $plugin = $this->plugin_data();
733
  $plugin_name = $plugin['Name'];
734
+
735
  // Args to add to query if user opts in to tracking
736
  $yes_args = array(
737
  'plugin' => $this->plugin_name,
738
  'plugin_action' => 'yes'
739
  );
740
+
741
  // Decide how to request permission to collect email addresses
742
  if( $this->marketing == 1 ) {
743
  // Option 1 combines permissions to track and collect email
751
  'plugin' => $this->plugin_name,
752
  'plugin_action' => 'no'
753
  ) );
754
+
755
  // Decide on notice text
756
  if( $this->marketing != 1 ) {
757
  // Standard notice text
758
+ $notice_text = sprintf(
759
+ __( 'Thank you for installing our %1$s. We would like to track its usage on your site. We don\'t record any sensitive data, only information regarding the WordPress environment and %1$s settings, which we will use to help us make improvements to the %1$s. Tracking is completely optional.', 'singularity' ),
760
+ $this->what_am_i
761
+ );
762
  } else {
763
  // If we have option 1 for marketing, we include reference to sending product information here
764
+ $notice_text = sprintf(
765
+ __( 'Thank you for installing our %1$s. We\'d like your permission to track its usage on your site and subscribe you to our newsletter. We won\'t record any sensitive data, only information regarding the WordPress environment and %1$s settings, which we will use to help us make improvements to the %1$s. Tracking is completely optional.', 'singularity' ),
766
+ $this->what_am_i
767
+ );
768
  }
769
  // And we allow you to filter the text anyway
770
  $notice_text = apply_filters( 'wisdom_notice_text_' . esc_attr( $this->plugin_name ), $notice_text ); ?>
771
+
772
  <div class="notice notice-info updated put-dismiss-notice">
773
  <p><?php echo '<strong>' . esc_html( $plugin_name ) . '</strong>'; ?></p>
774
  <p><?php echo esc_html( $notice_text ); ?></p>
775
  <p>
776
+ <a href="<?php echo esc_url( $url_yes ); ?>" class="button-secondary"><?php _e( 'Allow', 'singularity' ); ?></a>
777
+ <a href="<?php echo esc_url( $url_no ); ?>" class="button-secondary"><?php _e( 'Do Not Allow', 'singularity' ); ?></a>
778
  </p>
779
  </div>
780
  <?php
781
  }
782
+
783
  }
784
+
785
  /**
786
  * Display the marketing notice to users if enabled
787
  * Only displays after the user has opted in to tracking
809
  'plugin' => $this->plugin_name,
810
  'marketing_optin' => 'no'
811
  ) );
812
+
813
+ $marketing_text = sprintf(
814
+ __( 'Thank you for opting in to tracking. Would you like to receive occasional news about this %s, including details of new features and special offers?', 'singularity' ),
815
+ $this->what_am_i
816
+ );
817
  $marketing_text = apply_filters( 'wisdom_marketing_text_' . esc_attr( $this->plugin_name ), $marketing_text ); ?>
818
+
819
  <div class="notice notice-info updated put-dismiss-notice">
820
  <p><?php echo '<strong>' . esc_html( $plugin_name ) . '</strong>'; ?></p>
821
  <p><?php echo esc_html( $marketing_text ); ?></p>
822
  <p>
823
+ <a href="<?php echo esc_url( $url_yes ); ?>" data-putnotice="yes" class="button-secondary"><?php _e( 'Yes Please', 'singularity' ); ?></a>
824
+ <a href="<?php echo esc_url( $url_no ); ?>" data-putnotice="no" class="button-secondary"><?php _e( 'No Thank You', 'singularity' ); ?></a>
825
  </p>
826
  </div>
827
  <?php }
828
  }
829
+
830
  /**
831
  * Filter the deactivation link to allow us to present a form when the user deactivates the plugin
832
  * @since 1.0.0
844
  }
845
  return $links;
846
  }
847
+
848
  /*
849
  * Form text strings
850
  * These are non-filterable and used as fallback in case filtered strings aren't set correctly
852
  */
853
  public function form_default_text() {
854
  $form = array();
855
+ $form['heading'] = __( 'Sorry to see you go', 'singularity' );
856
+ $form['body'] = __( 'Before you deactivate the plugin, would you quickly give us your reason for doing so?', 'singularity' );
857
  $form['options'] = array(
858
+ __( 'Set up is too difficult', 'singularity' ),
859
+ __( 'Lack of documentation', 'singularity' ),
860
+ __( 'Not the features I wanted', 'singularity' ),
861
+ __( 'Found a better plugin', 'singularity' ),
862
+ __( 'Installed by mistake', 'singularity' ),
863
+ __( 'Only required temporarily', 'singularity' ),
864
+ __( 'Didn\'t work', 'singularity' )
865
  );
866
+ $form['details'] = __( 'Details (optional)', 'singularity' );
867
  return $form;
868
  }
869
+
870
  /**
871
  * Form text strings
872
  * These can be filtered
877
  $form = $this->form_default_text();
878
  return apply_filters( 'wisdom_form_text_' . esc_attr( $this->plugin_name ), $form );
879
  }
880
+
881
  /**
882
  * Form text strings
883
  * These can be filtered
902
  $html .= '</div><!-- .put-goodbye-options -->';
903
  }
904
  $html .= '</div><!-- .put-goodbye-form-body -->';
905
+ $html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'singularity' ) . '</p>';
906
  ?>
907
  <div class="put-goodbye-form-bg"></div>
908
  <style type="text/css">
962
  var url = document.getElementById("put-goodbye-link-<?php echo esc_attr( $this->plugin_name ); ?>");
963
  $('body').toggleClass('put-form-active');
964
  $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?>").fadeIn();
965
+ $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?>").html( '<?php echo $html; ?>' + '<div class="put-goodbye-form-footer"><p><a id="put-submit-form" class="button primary" href="#"><?php _e( 'Submit and Deactivate', 'singularity' ); ?></a>&nbsp;<a class="secondary button" href="'+url+'"><?php _e( 'Just Deactivate', 'singularity' ); ?></a></p></div>');
966
  $('#put-submit-form').on('click', function(e){
967
  // As soon as we click, the body of the form should disappear
968
  $("#put-goodbye-form-<?php echo esc_attr( $this->plugin_name ); ?> .put-goodbye-form-body").fadeOut();
1000
  });
1001
  </script>
1002
  <?php }
1003
+
1004
  /**
1005
  * AJAX callback when the form is submitted
1006
  * @since 1.0.0
1019
  echo 'success';
1020
  wp_die();
1021
  }
1022
+
1023
  }
1024
+
1025
+ }
uk-cookie-consent.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Cookie Consent
4
  Plugin URI: https://catapultthemes.com/cookie-consent/
5
  Description: The only cookie consent plugin you'll ever need.
6
- Version: 2.3.7
7
  Author: Catapult_Themes
8
  Author URI: https://catapultthemes.com/
9
  Text Domain: uk-cookie-consent
@@ -24,7 +24,7 @@ if ( is_admin() ) {
24
  require_once dirname( __FILE__ ) . '/admin/class-ctcc-admin.php';
25
  $CTCC_Admin = new CTCC_Admin();
26
  $CTCC_Admin -> init();
27
-
28
  $options = get_option( 'ctcc_options_settings' );
29
  // Add the metafield if enabled
30
  if( ! empty( $options['enable_metafield'] ) ) {
@@ -96,4 +96,4 @@ if( ! function_exists( 'uk_cookie_consent_start_plugin_tracking' ) ) {
96
  );
97
  }
98
  uk_cookie_consent_start_plugin_tracking();
99
- }
3
  Plugin Name: Cookie Consent
4
  Plugin URI: https://catapultthemes.com/cookie-consent/
5
  Description: The only cookie consent plugin you'll ever need.
6
+ Version: 2.3.8
7
  Author: Catapult_Themes
8
  Author URI: https://catapultthemes.com/
9
  Text Domain: uk-cookie-consent
24
  require_once dirname( __FILE__ ) . '/admin/class-ctcc-admin.php';
25
  $CTCC_Admin = new CTCC_Admin();
26
  $CTCC_Admin -> init();
27
+
28
  $options = get_option( 'ctcc_options_settings' );
29
  // Add the metafield if enabled
30
  if( ! empty( $options['enable_metafield'] ) ) {
96
  );
97
  }
98
  uk_cookie_consent_start_plugin_tracking();
99
+ }