Cookie Notice by dFactory - Version 2.4.2

Version Description

  • New: Compatibility with Autoptimize plugin
  • Fix: Improved Contact Form 7 reCaptcha support
  • Fix: Fixed non-static method cookies_set()
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Cookie Notice by dFactory
Version 2.4.2
Comparing to
See all releases

Code changes from version 2.4.1 to 2.4.2

cookie-notice.php CHANGED
@@ -2,10 +2,10 @@
2
  /*
3
  Plugin Name: Cookie Notice & Compliance for GDPR / CCPA
4
  Description: Cookie Notice allows you to you elegantly inform users that your site uses cookies and helps you comply with GDPR, CCPA and other data privacy laws.
5
- Version: 2.4.1
6
  Author: Hu-manity.co
7
  Author URI: https://hu-manity.co/
8
- Plugin URI: https://hu-manity.co/
9
  License: MIT License
10
  License URI: https://opensource.org/licenses/MIT
11
  Text Domain: cookie-notice
@@ -29,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) )
29
  * Cookie Notice class.
30
  *
31
  * @class Cookie_Notice
32
- * @version 2.4.1
33
  */
34
  class Cookie_Notice {
35
 
@@ -43,7 +43,6 @@ class Cookie_Notice {
43
  private $transactional_api_url = 'https://transactional-api.hu-manity.co';
44
  private $app_widget_url = '//cdn.hu-manity.co/hu-banner.min.js';
45
  private $deactivaion_url = '';
46
- private $plugin_basename = '';
47
  private $network_admin = false;
48
  private $plugin_network_active = false;
49
  private static $_instance;
@@ -106,7 +105,7 @@ class Cookie_Notice {
106
  'update_delay_date' => 0,
107
  'update_threshold_date' => 0
108
  ],
109
- 'version' => '2.4.1'
110
  ];
111
 
112
  /**
@@ -219,6 +218,8 @@ class Cookie_Notice {
219
  */
220
  private function define_constants() {
221
  define( 'COOKIE_NOTICE_URL', plugins_url( '', __FILE__ ) );
 
 
222
  }
223
 
224
  /**
@@ -339,14 +340,11 @@ class Cookie_Notice {
339
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
340
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
341
 
342
- // get plugin "dir/file" path
343
- $this->plugin_basename = plugin_basename( __FILE__ );
344
-
345
  // bypass is_network_admin() to handle AJAX requests properly.
346
  $this->network_admin = is_multisite() && ( is_network_admin() || ( wp_doing_ajax() && isset( $_POST['cn_network'] ) && $_POST['cn_network'] === '1' ) );
347
 
348
  // check whether the plugin is active for the entire network.
349
- $this->plugin_network_active = is_plugin_active_for_network( $this->plugin_basename );
350
  }
351
 
352
  /**
@@ -355,17 +353,14 @@ class Cookie_Notice {
355
  * @return void
356
  */
357
  private function includes() {
358
- // get plugin path
359
- $path = plugin_dir_path( __FILE__ );
360
-
361
- include_once( $path . 'includes/bot-detect.php' );
362
- include_once( $path . 'includes/dashboard.php' );
363
- include_once( $path . 'includes/frontend.php' );
364
- include_once( $path . 'includes/functions.php' );
365
- include_once( $path . 'includes/settings.php' );
366
- include_once( $path . 'includes/welcome.php' );
367
- include_once( $path . 'includes/welcome-api.php' );
368
- include_once( $path . 'includes/welcome-frontend.php' );
369
  }
370
 
371
  /**
@@ -374,7 +369,7 @@ class Cookie_Notice {
374
  * @return void
375
  */
376
  public function load_textdomain() {
377
- load_plugin_textdomain( 'cookie-notice', false, dirname( $this->plugin_basename ) . '/languages/' );
378
  }
379
 
380
  /**
@@ -445,6 +440,7 @@ class Cookie_Notice {
445
  delete_site_option( 'cookie_notice_options' );
446
  delete_site_option( 'cookie_notice_status' );
447
  delete_site_option( 'cookie_notice_app_analytics' );
 
448
  delete_site_option( 'cookie_notice_version' );
449
  }
450
 
@@ -483,10 +479,11 @@ class Cookie_Notice {
483
  delete_option( 'cookie_notice_options' );
484
  delete_option( 'cookie_notice_status' );
485
  delete_option( 'cookie_notice_app_analytics' );
 
486
  delete_option( 'cookie_notice_version' );
487
 
488
  // delete transient
489
- delete_transient( 'cookie_notice_compliance_cache' );
490
  }
491
 
492
  // remove wp super cache cookie
@@ -888,7 +885,7 @@ class Cookie_Notice {
888
  *
889
  * @return boolean
890
  */
891
- public function cookies_set() {
892
  if ( Cookie_Notice()->get_status() === 'active' )
893
  $result = isset( $_COOKIE['hu-consent'] );
894
  else
@@ -988,7 +985,7 @@ class Cookie_Notice {
988
  if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
989
  return $links;
990
 
991
- if ( $file === $this->plugin_basename ) {
992
  if ( ! empty( $links['deactivate'] ) ) {
993
  // link already contains class attribute?
994
  if ( preg_match( '/<a.*?class=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 )
2
  /*
3
  Plugin Name: Cookie Notice & Compliance for GDPR / CCPA
4
  Description: Cookie Notice allows you to you elegantly inform users that your site uses cookies and helps you comply with GDPR, CCPA and other data privacy laws.
5
+ Version: 2.4.2
6
  Author: Hu-manity.co
7
  Author URI: https://hu-manity.co/
8
+ Plugin URI: https://cookie-compliance.co/
9
  License: MIT License
10
  License URI: https://opensource.org/licenses/MIT
11
  Text Domain: cookie-notice
29
  * Cookie Notice class.
30
  *
31
  * @class Cookie_Notice
32
+ * @version 2.4.2
33
  */
34
  class Cookie_Notice {
35
 
43
  private $transactional_api_url = 'https://transactional-api.hu-manity.co';
44
  private $app_widget_url = '//cdn.hu-manity.co/hu-banner.min.js';
45
  private $deactivaion_url = '';
 
46
  private $network_admin = false;
47
  private $plugin_network_active = false;
48
  private static $_instance;
105
  'update_delay_date' => 0,
106
  'update_threshold_date' => 0
107
  ],
108
+ 'version' => '2.4.2'
109
  ];
110
 
111
  /**
218
  */
219
  private function define_constants() {
220
  define( 'COOKIE_NOTICE_URL', plugins_url( '', __FILE__ ) );
221
+ define( 'COOKIE_NOTICE_PATH', plugin_dir_path( __FILE__ ) );
222
+ define( 'COOKIE_NOTICE_BASENAME', plugin_basename( __FILE__ ) );
223
  }
224
 
225
  /**
340
  if ( ! function_exists( 'is_plugin_active_for_network' ) )
341
  require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
342
 
 
 
 
343
  // bypass is_network_admin() to handle AJAX requests properly.
344
  $this->network_admin = is_multisite() && ( is_network_admin() || ( wp_doing_ajax() && isset( $_POST['cn_network'] ) && $_POST['cn_network'] === '1' ) );
345
 
346
  // check whether the plugin is active for the entire network.
347
+ $this->plugin_network_active = is_plugin_active_for_network( COOKIE_NOTICE_BASENAME );
348
  }
349
 
350
  /**
353
  * @return void
354
  */
355
  private function includes() {
356
+ include_once( COOKIE_NOTICE_PATH . 'includes/bot-detect.php' );
357
+ include_once( COOKIE_NOTICE_PATH . 'includes/dashboard.php' );
358
+ include_once( COOKIE_NOTICE_PATH . 'includes/frontend.php' );
359
+ include_once( COOKIE_NOTICE_PATH . 'includes/functions.php' );
360
+ include_once( COOKIE_NOTICE_PATH . 'includes/settings.php' );
361
+ include_once( COOKIE_NOTICE_PATH . 'includes/welcome.php' );
362
+ include_once( COOKIE_NOTICE_PATH . 'includes/welcome-api.php' );
363
+ include_once( COOKIE_NOTICE_PATH . 'includes/welcome-frontend.php' );
 
 
 
364
  }
365
 
366
  /**
369
  * @return void
370
  */
371
  public function load_textdomain() {
372
+ load_plugin_textdomain( 'cookie-notice', false, dirname( COOKIE_NOTICE_BASENAME ) . '/languages/' );
373
  }
374
 
375
  /**
440
  delete_site_option( 'cookie_notice_options' );
441
  delete_site_option( 'cookie_notice_status' );
442
  delete_site_option( 'cookie_notice_app_analytics' );
443
+ delete_site_option( 'cookie_notice_app_blocking' );
444
  delete_site_option( 'cookie_notice_version' );
445
  }
446
 
479
  delete_option( 'cookie_notice_options' );
480
  delete_option( 'cookie_notice_status' );
481
  delete_option( 'cookie_notice_app_analytics' );
482
+ delete_option( 'cookie_notice_app_blocking' );
483
  delete_option( 'cookie_notice_version' );
484
 
485
  // delete transient
486
+ delete_transient( 'cookie_notice_app_cache' );
487
  }
488
 
489
  // remove wp super cache cookie
885
  *
886
  * @return boolean
887
  */
888
+ public static function cookies_set() {
889
  if ( Cookie_Notice()->get_status() === 'active' )
890
  $result = isset( $_COOKIE['hu-consent'] );
891
  else
985
  if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
986
  return $links;
987
 
988
+ if ( $file === COOKIE_NOTICE_BASENAME ) {
989
  if ( ! empty( $links['deactivate'] ) ) {
990
  // link already contains class attribute?
991
  if ( preg_match( '/<a.*?class=(\'|")(.*?)(\'|").*?>/is', $links['deactivate'], $result ) === 1 )
includes/frontend.php CHANGED
@@ -20,6 +20,7 @@ class Cookie_Notice_Frontend {
20
  */
21
  public function __construct() {
22
  // actions
 
23
  add_action( 'init', [ $this, 'init' ] );
24
  }
25
 
@@ -35,30 +36,36 @@ class Cookie_Notice_Frontend {
35
  if ( isset( $_GET['hu_purge_cache'] ) )
36
  $this->purge_cache();
37
 
 
 
 
38
  // is it preview mode?
39
  $this->preview_mode = isset( $_GET['cn_preview_mode'] );
40
 
41
  // is it a bot?
42
- $this->is_bot = Cookie_Notice()->bot_detect->is_crawler();
43
 
44
  // is user logged in and hiding the banner is enabled
45
- $this->hide_banner = is_user_logged_in() && Cookie_Notice()->options['general']['hide_banner'] === true;
46
 
47
  global $pagenow;
48
 
49
  // bail if in preview mode or it's a bot request
50
  if ( ! $this->preview_mode && ! $this->is_bot && ! $this->hide_banner && ! ( is_admin() && $pagenow === 'widgets.php' && isset( $_GET['legacy-widget-preview'] ) ) ) {
51
  // init cookie compliance
52
- if ( Cookie_Notice()->get_status() === 'active' ) {
53
  add_action( 'send_headers', [ $this, 'add_compliance_http_header' ] );
54
  add_action( 'wp_head', [ $this, 'add_cookie_compliance' ], 0 );
55
 
56
- // contact form 7 5.1+ recaptcha v3 compatibility
57
- if ( class_exists( 'WPCF7' ) && class_exists( 'WPCF7_RECAPTCHA' ) && defined( 'WPCF7_VERSION' ) && version_compare( WPCF7_VERSION, '5.1', '>=' ) ) {
58
- $service = WPCF7_RECAPTCHA::get_instance();
59
 
60
- if ( $service->is_active() )
61
- add_action( 'wp_enqueue_scripts', [ $this, 'contact_form_7_recaptcha' ], 21 );
 
 
 
62
  }
63
  // init cookie notice
64
  } else {
@@ -75,47 +82,6 @@ class Cookie_Notice_Frontend {
75
  }
76
  }
77
 
78
- /**
79
- * Replace original recaptcha script from Contact Form 7.
80
- *
81
- * @return void
82
- */
83
- public function contact_form_7_recaptcha() {
84
- // deregister original script
85
- wp_deregister_script( 'wpcf7-recaptcha' );
86
-
87
- $service = WPCF7_RECAPTCHA::get_instance();
88
-
89
- // register new script
90
- wp_register_script(
91
- 'wpcf7-recaptcha',
92
- COOKIE_NOTICE_URL . '/includes/modules/contact-form-7/recaptcha.js',
93
- [
94
- 'google-recaptcha',
95
- 'wp-polyfill',
96
- ],
97
- WPCF7_VERSION,
98
- true
99
- );
100
-
101
- wp_enqueue_script( 'wpcf7-recaptcha' );
102
-
103
- wp_localize_script(
104
- 'wpcf7-recaptcha',
105
- 'wpcf7_recaptcha',
106
- [
107
- 'sitekey' => $service->get_sitekey(),
108
- 'actions' => apply_filters(
109
- 'wpcf7_recaptcha_actions',
110
- [
111
- 'homepage' => 'homepage',
112
- 'contactform' => 'contactform'
113
- ]
114
- )
115
- ]
116
- );
117
- }
118
-
119
  /**
120
  * Add CORS header for API requests and purge cache.
121
  *
@@ -153,12 +119,28 @@ class Cookie_Notice_Frontend {
153
  ]
154
  );
155
 
 
156
  if ( $cn->options['general']['debug_mode'] )
157
  $options['debugMode'] = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  // message output
160
  $output = '
161
- <!-- Hu Banner -->
162
  <script type="text/javascript">
163
  var huOptions = ' . json_encode( $options ) . ';
164
  </script>
@@ -360,6 +342,47 @@ class Cookie_Notice_Frontend {
360
  echo $scripts;
361
  }
362
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  /**
365
  * Add new body classes.
20
  */
21
  public function __construct() {
22
  // actions
23
+ // add_action( 'plugins_loaded', [ $this, 'init_modules' ] );
24
  add_action( 'init', [ $this, 'init' ] );
25
  }
26
 
36
  if ( isset( $_GET['hu_purge_cache'] ) )
37
  $this->purge_cache();
38
 
39
+ // get main instance
40
+ $cn = Cookie_Notice();
41
+
42
  // is it preview mode?
43
  $this->preview_mode = isset( $_GET['cn_preview_mode'] );
44
 
45
  // is it a bot?
46
+ $this->is_bot = $cn->bot_detect->is_crawler();
47
 
48
  // is user logged in and hiding the banner is enabled
49
+ $this->hide_banner = is_user_logged_in() && $cn->options['general']['hide_banner'] === true;
50
 
51
  global $pagenow;
52
 
53
  // bail if in preview mode or it's a bot request
54
  if ( ! $this->preview_mode && ! $this->is_bot && ! $this->hide_banner && ! ( is_admin() && $pagenow === 'widgets.php' && isset( $_GET['legacy-widget-preview'] ) ) ) {
55
  // init cookie compliance
56
+ if ( $cn->get_status() === 'active' ) {
57
  add_action( 'send_headers', [ $this, 'add_compliance_http_header' ] );
58
  add_action( 'wp_head', [ $this, 'add_cookie_compliance' ], 0 );
59
 
60
+ // autoptimize
61
+ if ( function_exists( 'autoptimize' ) )
62
+ include_once( COOKIE_NOTICE_PATH . 'includes/modules/autoptimize/autoptimize.php' );
63
 
64
+ // is blocking active?
65
+ if ( $cn->options['general']['app_blocking'] ) {
66
+ // contact form 7 5.1+ recaptcha v3 compatibility
67
+ if ( class_exists( 'WPCF7' ) && class_exists( 'WPCF7_RECAPTCHA' ) && defined( 'WPCF7_VERSION' ) && version_compare( WPCF7_VERSION, '5.1', '>=' ) )
68
+ include_once( COOKIE_NOTICE_PATH . 'includes/modules/contact-form-7/contact-form-7.php' );
69
  }
70
  // init cookie notice
71
  } else {
82
  }
83
  }
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  /**
86
  * Add CORS header for API requests and purge cache.
87
  *
119
  ]
120
  );
121
 
122
+ // debug mode
123
  if ( $cn->options['general']['debug_mode'] )
124
  $options['debugMode'] = true;
125
+
126
+ // custom scripts?
127
+ if ( (bool) $cn->options['general']['app_blocking'] ) { // $options['blocking'] === true
128
+ if ( is_multisite() && $cn->is_network_admin() && $cn->is_plugin_network_active() && $cn->network_options['global_override'] )
129
+ $blocking = get_site_option( 'cookie_notice_app_blocking' );
130
+ else
131
+ $blocking = get_option( 'cookie_notice_app_blocking' );
132
+
133
+ $providers = ! empty( $blocking[ 'providers'] ) && is_array( $blocking[ 'providers'] ) ? $this->get_custom_items( $blocking[ 'providers'] ) : [];
134
+
135
+ $patterns = ! empty( $blocking[ 'patterns'] ) && is_array( $blocking[ 'patterns'] ) ? $this->get_custom_items( $blocking[ 'patterns' ] ) : [];
136
+
137
+ $options['customProviders'] = ! empty( $providers ) ? $providers : [];
138
+ $options['customPatterns'] = ! empty( $patterns ) ? $patterns : [];
139
+ }
140
 
141
  // message output
142
  $output = '
143
+ <!-- Cookie Compliance -->
144
  <script type="text/javascript">
145
  var huOptions = ' . json_encode( $options ) . ';
146
  </script>
342
  echo $scripts;
343
  }
344
  }
345
+
346
+ /**
347
+ * Get custom providers or patterns.
348
+ *
349
+ * @param type $items
350
+ * @return type
351
+ */
352
+ public function get_custom_items( $items ) {
353
+ $result = [];
354
+
355
+ if ( ! empty( $items ) && is_array( $items ) ) {
356
+ foreach ( $items as $index => $item ) {
357
+ if ( isset( $item->IsCustom ) && $item->IsCustom == true ) {
358
+ $sanitized_item = [];
359
+
360
+ foreach ( $item as $key => $value ) {
361
+ $sanitized_item[$key] = $this->sanitize_field( $value, $key );
362
+ }
363
+
364
+ $result[] = (object) $sanitized_item;
365
+ }
366
+ }
367
+ }
368
+
369
+ return $result;
370
+ }
371
+
372
+ private function sanitize_field( $value, $key ) {
373
+ $sanitized_value = $value;
374
+
375
+ switch ( $key ) {
376
+ case 'CategoryID':
377
+ $sanitized_value = (int) $value;
378
+ break;
379
+ case 'IsCustom':
380
+ $sanitized_value = (bool) $value;
381
+ break;
382
+ }
383
+
384
+ return $sanitized_value;
385
+ }
386
 
387
  /**
388
  * Add new body classes.
includes/modules/autoptimize/autoptimize.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit;
5
+
6
+ /**
7
+ * Cookie Notice Modules Autoptimize class.
8
+ *
9
+ * @class Cookie_Notice_Modules_Autoptimize
10
+ */
11
+ class Cookie_Notice_Modules_Autoptimize {
12
+
13
+ /**
14
+ * Constructor.
15
+ *
16
+ * @return void
17
+ */
18
+ public function __construct() {
19
+ add_filter( 'autoptimize_filter_js_exclude', [ $this, 'exclude' ] );
20
+ }
21
+
22
+ /**
23
+ * Filter excluded JavaScript files or inline code.
24
+ *
25
+ * @param string $excludes
26
+ * @return string
27
+ */
28
+ function exclude( $excludes ) {
29
+ if ( empty( $excludes ) )
30
+ $new_excludes = [];
31
+ else {
32
+ $new_excludes = explode( ',', $excludes );
33
+ $new_excludes = array_filter( $new_excludes );
34
+ $new_excludes = array_map( 'trim', $new_excludes );
35
+ }
36
+
37
+ // not found huOptions?
38
+ if ( strpos( $excludes, 'huOptions' ) === false )
39
+ $new_excludes[] = 'huOptions';
40
+
41
+ // get widget url
42
+ $widget_url = basename( Cookie_Notice()->get_url( 'widget' ) );
43
+
44
+ // not found widget url?
45
+ if ( strpos( $excludes, $widget_url ) === false )
46
+ $new_excludes[] = $widget_url;
47
+
48
+ return implode( ', ', $new_excludes );
49
+ }
50
+ }
51
+
52
+ new Cookie_Notice_Modules_Autoptimize();
includes/modules/contact-form-7/contact-form-7.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) )
4
+ exit;
5
+
6
+ /**
7
+ * Cookie Notice Modules Contact Form 7 class.
8
+ *
9
+ * @class Cookie_Notice_Modules_ContactForm7
10
+ */
11
+ class Cookie_Notice_Modules_ContactForm7 {
12
+
13
+ private $service;
14
+
15
+ /**
16
+ * Constructor.
17
+ *
18
+ * @return void
19
+ */
20
+ public function __construct() {
21
+ $this->service = WPCF7_RECAPTCHA::get_instance();
22
+
23
+ if ( $this->service->is_active() )
24
+ add_action( 'wp_enqueue_scripts', [ $this, 'contact_form_7_recaptcha' ], 21 );
25
+ }
26
+
27
+ /**
28
+ * Replace original recaptcha script from Contact Form 7.
29
+ *
30
+ * @return void
31
+ */
32
+ public function contact_form_7_recaptcha() {
33
+ // deregister original script
34
+ wp_deregister_script( 'wpcf7-recaptcha' );
35
+
36
+ // register new script
37
+ wp_register_script(
38
+ 'wpcf7-recaptcha',
39
+ COOKIE_NOTICE_URL . '/includes/modules/contact-form-7/recaptcha.js',
40
+ [
41
+ 'google-recaptcha',
42
+ 'wp-polyfill',
43
+ ],
44
+ WPCF7_VERSION,
45
+ true
46
+ );
47
+
48
+ wp_enqueue_script( 'wpcf7-recaptcha' );
49
+
50
+ wp_localize_script(
51
+ 'wpcf7-recaptcha',
52
+ 'wpcf7_recaptcha',
53
+ [
54
+ 'sitekey' => $this->service->get_sitekey(),
55
+ 'actions' => apply_filters(
56
+ 'wpcf7_recaptcha_actions',
57
+ [
58
+ 'homepage' => 'homepage',
59
+ 'contactform' => 'contactform'
60
+ ]
61
+ )
62
+ ]
63
+ );
64
+ }
65
+ }
66
+
67
+ new Cookie_Notice_Modules_ContactForm7();
includes/settings.php CHANGED
@@ -1134,9 +1134,9 @@ class Cookie_Notice_Settings {
1134
 
1135
  // purge cache on save
1136
  if ( $is_network )
1137
- delete_site_transient( 'cookie_notice_compliance_cache' );
1138
  else
1139
- delete_transient( 'cookie_notice_compliance_cache' );
1140
  } elseif ( isset( $_POST['reset_cookie_notice_options'] ) ) {
1141
  $input = $cn->defaults['general'];
1142
 
@@ -1148,13 +1148,13 @@ class Cookie_Notice_Settings {
1148
  update_site_option( 'cookie_notice_status', '' );
1149
 
1150
  // purge cache on save
1151
- delete_site_transient( 'cookie_notice_compliance_cache' );
1152
  } else {
1153
  // set app status
1154
  update_option( 'cookie_notice_status', '' );
1155
 
1156
  // purge cache on save
1157
- delete_transient( 'cookie_notice_compliance_cache' );
1158
  }
1159
  }
1160
 
@@ -1328,11 +1328,18 @@ class Cookie_Notice_Settings {
1328
 
1329
  if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
1330
  echo false;
 
 
 
1331
 
1332
- if ( Cookie_Notice()->is_network_admin() )
1333
- delete_site_transient( 'cookie_notice_compliance_cache' );
 
1334
  else
1335
- delete_transient( 'cookie_notice_compliance_cache' );
 
 
 
1336
 
1337
  echo true;
1338
  exit;
1134
 
1135
  // purge cache on save
1136
  if ( $is_network )
1137
+ delete_site_transient( 'cookie_notice_app_cache' );
1138
  else
1139
+ delete_transient( 'cookie_notice_app_cache' );
1140
  } elseif ( isset( $_POST['reset_cookie_notice_options'] ) ) {
1141
  $input = $cn->defaults['general'];
1142
 
1148
  update_site_option( 'cookie_notice_status', '' );
1149
 
1150
  // purge cache on save
1151
+ delete_site_transient( 'cookie_notice_app_cache' );
1152
  } else {
1153
  // set app status
1154
  update_option( 'cookie_notice_status', '' );
1155
 
1156
  // purge cache on save
1157
+ delete_transient( 'cookie_notice_app_cache' );
1158
  }
1159
  }
1160
 
1328
 
1329
  if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
1330
  echo false;
1331
+
1332
+ // get main instance
1333
+ $cn = Cookie_Notice();
1334
 
1335
+ // delete cache
1336
+ if ( $cn->is_network_admin() )
1337
+ delete_site_transient( 'cookie_notice_app_cache' );
1338
  else
1339
+ delete_transient( 'cookie_notice_app_cache' );
1340
+
1341
+ // request for new config data too
1342
+ $cn->welcome_api->get_app_config( true );
1343
 
1344
  echo true;
1345
  exit;
includes/welcome-api.php CHANGED
@@ -20,6 +20,7 @@ class Cookie_Notice_Welcome_API {
20
  // actions
21
  add_action( 'init', [ $this, 'check_cron' ] );
22
  add_action( 'cookie_notice_get_app_analytics', [ $this, 'get_app_analytics' ] );
 
23
  add_action( 'wp_ajax_cn_api_request', [ $this, 'api_request' ] );
24
  }
25
 
@@ -360,18 +361,18 @@ class Cookie_Notice_Welcome_API {
360
  update_site_option( 'cookie_notice_options', $cn->options['general'] );
361
 
362
  // purge cache
363
- delete_site_transient( 'cookie_notice_compliance_cache' );
364
 
365
  // get options
366
- $app_config = get_site_transient( 'cookie_notice_app_config' );
367
  } else {
368
  update_option( 'cookie_notice_options', $cn->options['general'] );
369
 
370
  // purge cache
371
- delete_transient( 'cookie_notice_compliance_cache' );
372
 
373
  // get options
374
- $app_config = get_transient( 'cookie_notice_app_config' );
375
  }
376
 
377
  // create quick config
@@ -598,12 +599,12 @@ class Cookie_Notice_Welcome_API {
598
  update_site_option( 'cookie_notice_options', $cn->options['general'] );
599
 
600
  // purge cache
601
- delete_site_transient( 'cookie_notice_compliance_cache' );
602
  } else {
603
  update_option( 'cookie_notice_options', $cn->options['general'] );
604
 
605
  // purge cache
606
- delete_transient( 'cookie_notice_compliance_cache' );
607
  }
608
 
609
  // create quick config
@@ -843,9 +844,9 @@ class Cookie_Notice_Welcome_API {
843
 
844
  // set options
845
  if ( $network )
846
- set_site_transient( 'cookie_notice_app_config', $options, 24 * HOUR_IN_SECONDS );
847
  else
848
- set_transient( 'cookie_notice_app_config', $options, 24 * HOUR_IN_SECONDS );
849
  break;
850
 
851
  case 'select_plan':
@@ -1109,14 +1110,55 @@ class Cookie_Notice_Welcome_API {
1109
  if ( Cookie_Notice()->get_status() === 'active' ) {
1110
  if ( ! wp_next_scheduled( 'cookie_notice_get_app_analytics' ) ) {
1111
  // set schedule
1112
- wp_schedule_event( time(), 'hourly', 'cookie_notice_get_app_analytics' ); // hourly
1113
  }
1114
- } elseif ( wp_next_scheduled( 'cookie_notice_get_app_analytics' ) )
1115
- wp_clear_scheduled_hook( 'cookie_notice_get_app_analytics' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1116
  }
1117
 
1118
  /**
1119
- * Get app config.
1120
  *
1121
  * @return array
1122
  */
@@ -1173,18 +1215,42 @@ class Cookie_Notice_Welcome_API {
1173
  }
1174
  }
1175
  }
1176
-
1177
  /**
1178
- * Get app status.
1179
  *
1180
- * @return bool|string
1181
  */
1182
- public function get_app_status( $app_id ) {
1183
- $result = '';
 
1184
 
1185
- if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
1186
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
 
 
 
 
 
 
 
1188
  $response = $this->request(
1189
  'get_config',
1190
  [
@@ -1192,18 +1258,25 @@ class Cookie_Notice_Welcome_API {
1192
  ]
1193
  );
1194
 
1195
- if ( ! empty( $response->data ) )
1196
- $result = 'active';
1197
- else {
1198
- if ( ! empty( $response->error ) ) {
1199
- if ( $response->error == 'App is not published yet' )
1200
- $result = 'pending';
 
 
 
 
 
 
 
 
 
1201
  else
1202
- $result = '';
1203
  }
1204
  }
1205
-
1206
- return $result;
1207
  }
1208
 
1209
  /**
20
  // actions
21
  add_action( 'init', [ $this, 'check_cron' ] );
22
  add_action( 'cookie_notice_get_app_analytics', [ $this, 'get_app_analytics' ] );
23
+ add_action( 'cookie_notice_get_app_config', [ $this, 'get_app_config' ] );
24
  add_action( 'wp_ajax_cn_api_request', [ $this, 'api_request' ] );
25
  }
26
 
361
  update_site_option( 'cookie_notice_options', $cn->options['general'] );
362
 
363
  // purge cache
364
+ delete_site_transient( 'cookie_notice_app_cache' );
365
 
366
  // get options
367
+ $app_config = get_site_transient( 'cookie_notice_app_quick_config' );
368
  } else {
369
  update_option( 'cookie_notice_options', $cn->options['general'] );
370
 
371
  // purge cache
372
+ delete_transient( 'cookie_notice_app_cache' );
373
 
374
  // get options
375
+ $app_config = get_transient( 'cookie_notice_app_quick_config' );
376
  }
377
 
378
  // create quick config
599
  update_site_option( 'cookie_notice_options', $cn->options['general'] );
600
 
601
  // purge cache
602
+ delete_site_transient( 'cookie_notice_app_cache' );
603
  } else {
604
  update_option( 'cookie_notice_options', $cn->options['general'] );
605
 
606
  // purge cache
607
+ delete_transient( 'cookie_notice_app_cache' );
608
  }
609
 
610
  // create quick config
844
 
845
  // set options
846
  if ( $network )
847
+ set_site_transient( 'cookie_notice_app_quick_config', $options, 24 * HOUR_IN_SECONDS );
848
  else
849
+ set_transient( 'cookie_notice_app_quick_config', $options, 24 * HOUR_IN_SECONDS );
850
  break;
851
 
852
  case 'select_plan':
1110
  if ( Cookie_Notice()->get_status() === 'active' ) {
1111
  if ( ! wp_next_scheduled( 'cookie_notice_get_app_analytics' ) ) {
1112
  // set schedule
1113
+ wp_schedule_event( time(), 'hourly', 'cookie_notice_get_app_analytics' );
1114
  }
1115
+ if ( ! wp_next_scheduled( 'cookie_notice_get_app_config' ) ) {
1116
+ // set schedule
1117
+ wp_schedule_event( time(), 'daily', 'cookie_notice_get_app_config' );
1118
+ }
1119
+ } else {
1120
+ if ( wp_next_scheduled( 'cookie_notice_get_app_analytics' ) )
1121
+ wp_clear_scheduled_hook( 'cookie_notice_get_app_analytics' );
1122
+
1123
+ if ( wp_next_scheduled( 'cookie_notice_get_app_config' ) )
1124
+ wp_clear_scheduled_hook( 'cookie_notice_get_app_config' );
1125
+ }
1126
+ }
1127
+
1128
+ /**
1129
+ * Get app status.
1130
+ *
1131
+ * @return bool|string
1132
+ */
1133
+ public function get_app_status( $app_id ) {
1134
+ $result = '';
1135
+
1136
+ if ( ! current_user_can( apply_filters( 'cn_manage_cookie_notice_cap', 'manage_options' ) ) )
1137
+ return false;
1138
+
1139
+ $response = $this->request(
1140
+ 'get_config',
1141
+ [
1142
+ 'AppID' => $app_id
1143
+ ]
1144
+ );
1145
+
1146
+ if ( ! empty( $response->data ) )
1147
+ $result = 'active';
1148
+ else {
1149
+ if ( ! empty( $response->error ) ) {
1150
+ if ( $response->error == 'App is not published yet' )
1151
+ $result = 'pending';
1152
+ else
1153
+ $result = '';
1154
+ }
1155
+ }
1156
+
1157
+ return $result;
1158
  }
1159
 
1160
  /**
1161
+ * Get app analytics.
1162
  *
1163
  * @return array
1164
  */
1215
  }
1216
  }
1217
  }
1218
+
1219
  /**
1220
+ * Get app config.
1221
  *
1222
+ * @return array
1223
  */
1224
+ public function get_app_config( $force_update = false ) {
1225
+ // get main instance
1226
+ $cn = Cookie_Notice();
1227
 
1228
+ $result = [];
1229
+ $allow_one_cron_per_hour = false;
1230
+
1231
+ if ( is_multisite() && $cn->is_plugin_network_active() && $cn->network_options['global_override'] ) {
1232
+ $app_id = $cn->network_options['app_id'];
1233
+ $network = true;
1234
+ $allow_one_cron_per_hour = true;
1235
+ } else {
1236
+ $app_id = $cn->options['general']['app_id'];
1237
+ $network = false;
1238
+ }
1239
+
1240
+ // in global override mode allow only one cron per hour
1241
+ if ( $allow_one_cron_per_hour && ! $force_update ) {
1242
+ $blocking = get_site_option( 'cookie_notice_app_blocking', [] );
1243
+
1244
+ // analytics data?
1245
+ if ( ! empty( $blocking ) ) {
1246
+ $updated = strtotime( $blocking['lastUpdated'] );
1247
 
1248
+ // last updated less than an hour?
1249
+ if ( $updated !== false && current_time( 'timestamp', true ) - $updated < 3600 )
1250
+ return;
1251
+ }
1252
+ }
1253
+
1254
  $response = $this->request(
1255
  'get_config',
1256
  [
1258
  ]
1259
  );
1260
 
1261
+ // get config
1262
+ if ( ! empty( $response->data ) ) {
1263
+ $result_raw = ! empty( $response->data ) ? map_deep( (array) $response->data, 'sanitize_text_field' ) : [];
1264
+
1265
+ // process blocking data
1266
+ if ( ! empty( $result_raw ) ) {
1267
+ $result['categories'] = ! empty( $result_raw['DefaultCategoryJSON'] ) && is_array( $result_raw['DefaultCategoryJSON'] ) ? $result_raw['DefaultCategoryJSON'] : [];
1268
+ $result['providers'] = ! empty( $result_raw['DefaultProviderJSON'] ) && is_array( $result_raw['DefaultProviderJSON'] ) ? $result_raw['DefaultProviderJSON'] : [];
1269
+ $result['patterns'] = ! empty( $result_raw['DefaultCookieJSON'] ) && is_array( $result_raw['DefaultCookieJSON'] ) ? $result_raw['DefaultCookieJSON'] : [];
1270
+
1271
+ // add time updated
1272
+ $result['lastUpdated'] = date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) );
1273
+
1274
+ if ( $network )
1275
+ update_site_option( 'cookie_notice_app_blocking', $result );
1276
  else
1277
+ update_option( 'cookie_notice_app_blocking', $result, false );
1278
  }
1279
  }
 
 
1280
  }
1281
 
1282
  /**
includes/welcome-frontend.php CHANGED
@@ -96,7 +96,7 @@ class Cookie_Notice_Welcome_Frontend {
96
  ];
97
 
98
  echo '
99
- <!-- Hu Banner -->
100
  <script type="text/javascript">
101
  var huOptions = ' . json_encode( $options ) . ';
102
  </script>
96
  ];
97
 
98
  echo '
99
+ <!-- Cookie Compliance -->
100
  <script type="text/javascript">
101
  var huOptions = ' . json_encode( $options ) . ';
102
  </script>
includes/welcome.php CHANGED
@@ -240,9 +240,6 @@ class Cookie_Notice_Welcome {
240
  <iframe id="cn_iframe_id" src="' . home_url( '/?cn_preview_mode=1' ) . '"></iframe>
241
  </div>';
242
  } elseif ( $screen == 3 ) {
243
- // get options
244
- // $app_config = get_transient( 'cookie_notice_app_config' );
245
-
246
  $html .= $this->welcome_screen( 'register', false );
247
 
248
  $html .= '
@@ -254,46 +251,6 @@ class Cookie_Notice_Welcome {
254
  <div class="cn-lead">
255
  <p>' . __( 'Take a proactive approach to data protection and consent laws by signing up for Cookie Compliance account. Then select a limited Basic Plan for free or get one of the Professional Plans for unlimited visits, consent storage, languages and customizations.', 'cookie-notice' ) . '</p>
256
  </div>';
257
- /*
258
- <div class="cn-billing-wrapper cn-radio-wrapper">
259
- <label for="cn_billing_monthly"><input id="cn_billing_monthly" type="radio" name="cn_billing" value="monthly" checked><span><span>' . __( 'Billing Monthly', 'cookie-notice' ) . '</span><span class="cn-plan-overlay"></span></span></label><label for="cn_billing_yearly"><input id="cn_billing_yearly" type="radio" name="cn_billing" value="yearly"><span><span>' . __( 'Billing Yearly', 'cookie-notice' ) . '</span> <span class="cn-price-off">(' . __( '15% off', 'cookie-notice' ) . ')</span><span class="cn-plan-overlay"></span></span></label>
260
- </div>
261
-
262
- $html .= '
263
- <div class="cn-hero-image">
264
- <div class="cn-flex-item">
265
- <div class="cn-logo-container">
266
- <img src="' . COOKIE_NOTICE_URL . '/img/cookie-notice-logo-dark.png">
267
- <span class="cn-badge">' . __( 'WP Plugin', 'cookie-notice' ) . '</span>
268
- </div>
269
- <img src="' . COOKIE_NOTICE_URL . '/img/screen-notice.png" alt="Cookie Notice dashboard" />
270
- <ul class="cn-features-list">
271
- <li><span>' . __( '<b>Free</b>', 'cookie-notice' ) . '</span></li>
272
- <li><span>' . __( 'Customizable notice message', 'cookie-notice' ) . '</span></li>
273
- <li><span>' . __( 'Consent on click, scroll or close', 'cookie-notice' ) . '</span></li>
274
- <li><span>' . __( 'Link to Privacy Policy page', 'cookie-notice' ) . '</span></li>
275
- </ul>
276
- </div>
277
- <div class="cn-flex-item">
278
- <img src="//cno0-53eb.kxcdn.com/screen-plus.png" alt="Cookie Notice + Compliance" />
279
- </div>
280
- <div class="cn-flex-item">
281
- <div class="cn-logo-container">
282
- <img src="' . COOKIE_NOTICE_URL . '/img/cookie-compliance-logo-dark.png">
283
- <span class="cn-badge">' . __( 'Web App', 'cookie-notice' ) . '</span>
284
- </div>
285
- <img src="' . COOKIE_NOTICE_URL . '/img/screen-compliance.png" alt="Cookie Compliance dashboard" />
286
- <ul class="cn-features-list">
287
- <li><span>' . __( '<b>Free plan</b>', 'cookie-notice' ) . '</span></li>
288
- <li><span>' . __( 'Consent Analytics Dashboard', 'cookie-notice' ) . '</span></li>
289
- <li><span>' . __( 'Cookie Autoblocking', 'cookie-notice' ) . '</span></li>
290
- <li><span>' . __( 'Cookie Categories', 'cookie-notice' ) . '</span></li>
291
- <li><span>' . __( 'Proof-of-Consent Storage', 'cookie-notice' ) . '</span></li>
292
- <li><span>' . __( "Link to 'Do Not Sell' page", 'cookie-notice' ) . '</span></li>
293
- </ul>
294
- </div>
295
- </div>';
296
- */
297
 
298
  $html .= '
299
  <h3 class="cn-pricing-select">' . __( 'Compliance Plans', 'cookie-notice' ) . ':</h3>
240
  <iframe id="cn_iframe_id" src="' . home_url( '/?cn_preview_mode=1' ) . '"></iframe>
241
  </div>';
242
  } elseif ( $screen == 3 ) {
 
 
 
243
  $html .= $this->welcome_screen( 'register', false );
244
 
245
  $html .= '
251
  <div class="cn-lead">
252
  <p>' . __( 'Take a proactive approach to data protection and consent laws by signing up for Cookie Compliance account. Then select a limited Basic Plan for free or get one of the Professional Plans for unlimited visits, consent storage, languages and customizations.', 'cookie-notice' ) . '</p>
253
  </div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  $html .= '
256
  <h3 class="cn-pricing-select">' . __( 'Compliance Plans', 'cookie-notice' ) . ':</h3>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: humanityco
3
  Tags: gdpr, ccpa, cookies, consent, compliance
4
  Requires at least: 4.7
5
  Requires PHP: 5.4
6
- Tested up to: 6.0.2
7
- Stable tag: 2.4.1
8
  License: MIT License
9
  License URI: http://opensource.org/licenses/MIT
10
 
@@ -121,6 +121,11 @@ Yes! The plugin + web appliaction version includes technical compliance features
121
 
122
  == Changelog ==
123
 
 
 
 
 
 
124
  = 2.4.1 =
125
  * New: Contact Form 7 reCaptcha support
126
  * Tweak: Switched health status from critical to recommended when Cookie Compliance is not integrated
@@ -433,7 +438,6 @@ Initial release
433
 
434
  == Upgrade Notice ==
435
 
436
- = 2.4.1 =
437
- * New: Contact Form 7 reCaptcha support
438
- * Tweak: Switched health status from critical to recommended when Cookie Compliance is not integrated
439
- * Tweak: Add SimeSite=Lax for created cookies
3
  Tags: gdpr, ccpa, cookies, consent, compliance
4
  Requires at least: 4.7
5
  Requires PHP: 5.4
6
+ Tested up to: 6.1
7
+ Stable tag: 2.4.2
8
  License: MIT License
9
  License URI: http://opensource.org/licenses/MIT
10
 
121
 
122
  == Changelog ==
123
 
124
+ = 2.4.2 =
125
+ * New: Compatibility with Autoptimize plugin
126
+ * Fix: Improved Contact Form 7 reCaptcha support
127
+ * Fix: Fixed non-static method cookies_set()
128
+
129
  = 2.4.1 =
130
  * New: Contact Form 7 reCaptcha support
131
  * Tweak: Switched health status from critical to recommended when Cookie Compliance is not integrated
438
 
439
  == Upgrade Notice ==
440
 
441
+ = 2.4.2 =
442
+ * New: Compatibility with Autoptimize plugin
443
+ * Fix: Improved Contact Form 7 reCaptcha support