PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.6.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.6.0
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / cookiebot.php
cookiebot Last commit date
addons 6 years ago assets 7 years ago css 6 years ago documentation 7 years ago js 6 years ago langs 8 years ago widgets 7 years ago CookiebotAPI.md 7 years ago LICENSE.txt 8 years ago README.md 7 years ago cookiebot-logo.png 8 years ago cookiebot.php 6 years ago phpunit.xml 7 years ago readme.txt 6 years ago
cookiebot.php
1716 lines
1 <?php
2 /*
3 Plugin Name: Cookiebot | GDPR/CCPA Compliant Cookie Consent and Control
4 Plugin URI: https://cookiebot.com/
5 Description: Cookiebot is a cloud-driven solution that automatically controls cookies and trackers, enabling full GDPR/ePrivacy and CCPA compliance for websites.
6 Author: Cybot A/S
7 Version: 3.6.0
8 Author URI: http://cookiebot.com
9 Text Domain: cookiebot
10 Domain Path: /langs
11 */
12
13 if(!defined('ABSPATH')) exit; // Exit if accessed directly
14
15 if(!class_exists('Cookiebot_WP')):
16
17 final class Cookiebot_WP {
18 /**
19 * Plugin version.
20 *
21 * @var string
22 * @since 1.0.0
23 */
24 public $version = '3.6.0';
25
26 /**
27 * @var Cookiebot_WP The single instance of the class
28 * @since 1.0.0
29 */
30 protected static $_instance = null;
31
32 /**
33 * Main Cookiebot_WP Instance
34 *
35 * Ensures only one instance of Cookiebot_WP is loaded or can be loaded.
36 *
37 * @version 1.0.0
38 * @since 1.0.0
39 * @static
40 * @return Cookiebot_WP - Main instance
41 */
42 public static function instance() {
43 if(is_null(self::$_instance)) {
44 self::$_instance = new self();
45 }
46 return self::$_instance;
47 }
48
49 /**
50 * Cookiebot_WP Constructor.
51 *
52 * @version 2.1.4
53 * @since 1.0.0
54 * @access public
55 */
56 function __construct() {
57 add_action('plugins_loaded', array($this, 'cookiebot_init'), 5);
58 register_activation_hook( __FILE__ , array($this, 'activation'));
59 register_deactivation_hook( __FILE__, 'cookiebot_addons_plugin_deactivated' );
60
61 $this->cookiebot_fix_plugin_conflicts();
62
63 }
64
65 /**
66 * Cookiebot_WP Installation actions
67 *
68 * @version 2.1.4
69 * @since 2.1.4
70 * @accces public
71 */
72 function activation() {
73 //Delay display of recommendation notice in 3 days if not activated ealier
74 if(get_option('cookiebot_notice_recommend',false) === false) {
75 //Not set yet - this must be first activation - delay in 3 days
76 update_option('cookiebot_notice_recommend', strtotime('+3 days'));
77 }
78 if($this->get_cbid() == '') {
79 if(is_multisite()) {
80 update_site_option('cookiebot-cookie-blocking-mode','auto');
81 update_site_option('cookiebot-nooutput-admin',true);
82 }
83 else {
84 update_option('cookiebot-cookie-blocking-mode','auto');
85 update_option('cookiebot-nooutput-admin',true);
86 }
87 }
88 }
89
90 /**
91 * Cookiebot_WP Init Cookiebot.
92 *
93 * @version 3.2.0
94 * @since 1.6.2
95 * @access public
96 */
97 function cookiebot_init() {
98 /* Load Cookiebot Addons Framework */
99 $dismissAddons = false;
100 if(defined('CAF_DIR')) {
101 $dismissAddons = true;
102 /*add_action('admin_notices', function() {
103 ?>
104 <div class="notice notice-warning">
105 <p>
106 <?php _e( 'You have Cookiebot Addons installed.', 'cookiebot' ); ?><br />
107 <?php _e( 'In this and future releases of Cookiebot all available Addons are bundled directly with the Cookiebot plugin.', 'cookiebot' ); ?><br />
108 <?php _e( 'To ensure up-to-date addons - please disable and remove your Cookiebot Addons plugin and configure you addons under "Prior consent" in the Cookiebot menu.', 'cookiebot' ); ?>
109 </p>
110 </div>
111 <?php
112 });*/
113 }
114 //elseif( $this->get_cookie_blocking_mode() !== 'auto' ) {
115 else {
116 if( (!defined('COOKIEBOT_ADDONS_STANDALONE') || COOKIEBOT_ADDONS_STANDALONE != true || !defined('COOKIE_ADDONS_LOADED')) && $dismissAddons !== true ) {
117 //Make sure we got a PHP version that works
118 if(version_compare(PHP_VERSION, '5.4.0', '>=')) {
119 define('COOKIEBOT_URL', plugin_dir_url( __FILE__ ));
120 include_once( dirname( __FILE__ ) . '/addons/cookiebot-addons-init.php' );
121 }
122 else {
123 define('COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION',true);
124 }
125 }
126 else {
127 add_action('admin_notices', function() {
128 ?>
129 <div class="notice notice-warning">
130 <p>
131 <?php _e( 'You are using Cookiebot Addons Standalone.', 'cookiebot' ); ?>
132 </p>
133 </div>
134 <?php
135 });
136 }
137 }
138 if(is_admin()) {
139
140 //Adding menu to WP admin
141 add_action('admin_menu', array($this,'add_menu'),1);
142 add_action('admin_menu', array($this,'add_menu_debug'),50);
143
144
145 if(is_multisite()) {
146 add_action('network_admin_menu', array($this,'add_network_menu'),1);
147 add_action('network_admin_edit_cookiebot_network_settings', array($this,'network_settings_save'));
148 }
149
150 //Register settings
151 add_action('admin_init', array($this,'register_cookiebot_settings'));
152
153 //Adding dashboard widgets
154 add_action('wp_dashboard_setup', array($this,'add_dashboard_widgets'));
155
156 add_action('admin_notices', array( $this, 'cookiebot_admin_notices' ) );
157 add_action('admin_init', array($this,'save_notice_link'));
158
159 //Check if we should show cookie consent banner on admin pages
160 if(!$this->cookiebot_disabled_in_admin()) {
161 //adding cookie banner in admin area too
162 add_action('admin_head', array($this,'add_js'),-9999);
163 }
164 }
165
166 //Include integration to WP Consent Level API if available
167 if($this->is_wp_consent_api_active()) {
168 add_action( 'wp_enqueue_scripts', array($this, 'cookiebot_enqueue_consent_api_scripts') );
169 }
170
171 // Set up localisation
172 load_plugin_textdomain('cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
173
174 //add JS
175 add_action('wp_head', array($this,'add_js'), -9999);
176 add_shortcode('cookie_declaration', array($this,'show_declaration'));
177
178 //Add filter if WP rocket is enabled
179 if(defined('WP_ROCKET_VERSION')) {
180 add_filter('rocket_minify_excluded_external_js', array($this,'wp_rocket_exclude_external_js'));
181 }
182
183 //Automatic update plugin
184 if(is_admin() || (defined('DOING_CRON') && DOING_CRON)) {
185 add_filter('auto_update_plugin', array($this,'automatic_updates'), 10, 2);
186 }
187
188 //Loading widgets
189 include_once( dirname( __FILE__ ) . '/widgets/cookiebot-declaration-widget.php' );
190 add_action( 'widgets_init', array($this,'register_widgets') );
191
192 }
193
194 /**
195 * Cookiebot_WP Load text domain
196 *
197 * @version 2.0.0
198 * @since 2.0.0
199 */
200 function load_textdomain() {
201 load_plugin_textdomain( 'cookiebot', false, basename( dirname( __FILE__ ) ) . '/langs' );
202 }
203
204 /**
205 * Cookiebot_WP Register widgets
206 *
207 * @version 2.5.0
208 * @since 2.5.0
209 */
210 function register_widgets() {
211 register_widget( 'Cookiebot_Declaration_Widget' );
212 }
213
214 /**
215 * Cookiebot_WP Add dashboard widgets to admin
216 *
217 * @version 1.0.0
218 * @since 1.0.0
219 */
220
221 function add_dashboard_widgets() {
222 wp_add_dashboard_widget('cookiebot_status', __('Cookiebot Status','cookiebot'), array($this,'dashboard_widget_status'));
223 }
224
225 /**
226 * Cookiebot_WP Output Dashboard Status Widget
227 *
228 * @version 1.0.0
229 * @since 1.0.0
230 */
231 function dashboard_widget_status() {
232 $cbid = $this->get_cbid();
233 if(empty($cbid)) {
234 echo '<p>'.__('You need to enter your Cookiebot ID.','cookiebot').'</p>';
235 echo '<p><a href="options-general.php?page=cookiebot">';
236 echo __('Update your Cookiebot ID','cookiebot');
237 echo '</a></p>';
238 }
239 else {
240 echo '<p>'._e('Your Cookiebot is working!','cookiebot').'</p>';
241 }
242 }
243
244 /**
245 * Cookiebot_WP Add option menu page for Cookiebot
246 *
247 * @version 2.2.0
248 * @since 1.0.0
249 */
250 function add_menu() {
251 //Cookiebot Icon SVG base64 encoded
252 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
253 add_menu_page( 'Cookiebot', __('Cookiebot','cookiebot'), 'manage_options', 'cookiebot', array($this,'settings_page'),$icon);
254
255 add_submenu_page('cookiebot',__('Cookiebot Settings','cookiebot'),__('Settings','cookiebot'), 'manage_options', 'cookiebot',array($this,'settings_page') );
256 add_submenu_page('cookiebot',__('Cookiebot Support','cookiebot'),__('Support','cookiebot'), 'manage_options', 'cookiebot_support',array($this,'support_page') );
257 add_submenu_page('cookiebot',__('IAB','cookiebot'),__('IAB','cookiebot'), 'manage_options', 'cookiebot_iab',array($this,'iab_page') );
258
259 if(defined('COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION')) {
260 //Load prior consent page anyway - but from Cookiebot WP Core plugin.
261 add_submenu_page( 'cookiebot', __( 'Prior Consent', 'cookiebot' ), __( 'Prior Consent', 'cookiebot' ), 'manage_options', 'cookiebot-addons', array($this,'setting_page_placeholder' ) );
262 }
263 }
264
265 /**
266 * Cookiebot_WP Add debug menu - we need to add this seperate to ensure it is placed last (after menu items from Addons).
267 *
268 * @version 3.6.0
269 * @since 3.6.0
270 */
271 function add_menu_debug() {
272 add_submenu_page('cookiebot',__('Debug info','cookiebot'),__('Debug info','cookiebot'), 'manage_options', 'cookiebot_debug',array($this,'debug_page') );
273 }
274
275 /**
276 * Cookiebot_WP Add menu for network sites
277 *
278 * @version 2.2.0
279 * @since 2.2.0
280 */
281 function add_network_menu() {
282 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
283 add_menu_page( 'Cookiebot', __('Cookiebot','cookiebot'), 'manage_network_options', 'cookiebot_network', array($this,'network_settings_page'),$icon);
284
285 add_submenu_page('cookiebot_network',__('Cookiebot Settings','cookiebot'),__('Settings','cookiebot'), 'network_settings_page', 'cookiebot_network',array($this,'network_settings_page'));
286 add_submenu_page('cookiebot_network',__('Cookiebot Support','cookiebot'),__('Support','cookiebot'), 'network_settings_page', 'cookiebot_support',array($this,'support_page'));
287
288 }
289
290 /**
291 * Cookiebot_WP Cookiebot prior consent placeholder page
292 *
293 * @version 1.4.0
294 * @since 1.0.0
295 */
296 function setting_page_placeholder() {
297 include __DIR__ . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'view/admin/settings/setting-page.php';
298 }
299
300 /**
301 * Cookiebot_WP Register Cookiebot settings
302 *
303 * @version 2.1.5
304 * @since 1.0.0
305 */
306 function register_cookiebot_settings() {
307 register_setting('cookiebot', 'cookiebot-cbid');
308 register_setting('cookiebot', 'cookiebot-language');
309 register_setting('cookiebot', 'cookiebot-nooutput');
310 register_setting('cookiebot', 'cookiebot-nooutput-admin');
311 register_setting('cookiebot', 'cookiebot-autoupdate');
312 register_setting('cookiebot', 'cookiebot-script-tag-uc-attribute');
313 register_setting('cookiebot', 'cookiebot-script-tag-cd-attribute');
314 register_setting('cookiebot', 'cookiebot-cookie-blocking-mode');
315 register_setting('cookiebot', 'cookiebot-consent-mapping');
316 register_setting('cookiebot-iab', 'cookiebot-iab');
317 }
318
319 /**
320 * Cookiebot_WP Automatic update plugin if activated
321 *
322 * @version 2.2.0
323 * @since 1.5.0
324 */
325 function automatic_updates($update, $item) {
326 //Do not update from subsite on a multisite installation
327 if(is_multisite() && ! is_main_site()) {
328 return $update;
329 }
330
331 //Check if we have everything we need
332 $item = (array)$item;
333 if(!isset($item['new_version']) || !isset($item['slug'])) {
334 return $update;
335 }
336
337 //It is not Cookiebot
338 if($item['slug'] !== 'cookiebot') {
339 return $update;
340 }
341
342 // Check if cookiebot autoupdate is disabled
343 if(!get_option('cookiebot-autoupdate',false)) {
344 return $update;
345 }
346
347 // Check if multisite autoupdate is disabled
348 if(is_multisite() && !get_site_option('cookiebot-autoupdate',false)) {
349 return $update;
350 }
351
352 return true;
353 }
354
355
356 /**
357 * Cookiebot_WP Get list of supported languages
358 *
359 * @version 1.4.0
360 * @since 1.4.0
361 */
362 public static function get_supported_languages() {
363 $supportedLanguages = array();
364 $supportedLanguages['nb'] = __('Norwegian Bokmål','cookiebot');
365 $supportedLanguages['tr'] = __('Turkish','cookiebot');
366 $supportedLanguages['de'] = __('German','cookiebot');
367 $supportedLanguages['cs'] = __('Czech','cookiebot');
368 $supportedLanguages['da'] = __('Danish','cookiebot');
369 $supportedLanguages['sq'] = __('Albanian','cookiebot');
370 $supportedLanguages['he'] = __('Hebrew','cookiebot');
371 $supportedLanguages['ko'] = __('Korean','cookiebot');
372 $supportedLanguages['it'] = __('Italian','cookiebot');
373 $supportedLanguages['nl'] = __('Dutch','cookiebot');
374 $supportedLanguages['vi'] = __('Vietnamese','cookiebot');
375 $supportedLanguages['ta'] = __('Tamil','cookiebot');
376 $supportedLanguages['is'] = __('Icelandic','cookiebot');
377 $supportedLanguages['ro'] = __('Romanian','cookiebot');
378 $supportedLanguages['si'] = __('Sinhala','cookiebot');
379 $supportedLanguages['ca'] = __('Catalan','cookiebot');
380 $supportedLanguages['bg'] = __('Bulgarian','cookiebot');
381 $supportedLanguages['uk'] = __('Ukrainian','cookiebot');
382 $supportedLanguages['zh'] = __('Chinese','cookiebot');
383 $supportedLanguages['en'] = __('English','cookiebot');
384 $supportedLanguages['ar'] = __('Arabic','cookiebot');
385 $supportedLanguages['hr'] = __('Croatian','cookiebot');
386 $supportedLanguages['th'] = __('Thai','cookiebot');
387 $supportedLanguages['el'] = __('Greek','cookiebot');
388 $supportedLanguages['lt'] = __('Lithuanian','cookiebot');
389 $supportedLanguages['pl'] = __('Polish','cookiebot');
390 $supportedLanguages['lv'] = __('Latvian','cookiebot');
391 $supportedLanguages['fr'] = __('French','cookiebot');
392 $supportedLanguages['id'] = __('Indonesian','cookiebot');
393 $supportedLanguages['mk'] = __('Macedonian','cookiebot');
394 $supportedLanguages['et'] = __('Estonian','cookiebot');
395 $supportedLanguages['pt'] = __('Portuguese','cookiebot');
396 $supportedLanguages['ga'] = __('Irish','cookiebot');
397 $supportedLanguages['ms'] = __('Malay','cookiebot');
398 $supportedLanguages['sl'] = __('Slovenian','cookiebot');
399 $supportedLanguages['ru'] = __('Russian','cookiebot');
400 $supportedLanguages['ja'] = __('Japanese','cookiebot');
401 $supportedLanguages['hi'] = __('Hindi','cookiebot');
402 $supportedLanguages['sk'] = __('Slovak','cookiebot');
403 $supportedLanguages['es'] = __('Spanish','cookiebot');
404 $supportedLanguages['sv'] = __('Swedish','cookiebot');
405 $supportedLanguages['sr'] = __('Serbian','cookiebot');
406 $supportedLanguages['fi'] = __('Finnish','cookiebot');
407 $supportedLanguages['eu'] = __('Basque','cookiebot');
408 $supportedLanguages['hu'] = __('Hungarian','cookiebot');
409 asort($supportedLanguages,SORT_LOCALE_STRING);
410 return $supportedLanguages;
411 }
412
413 /**
414 * Cookiebot_WP Output settings page
415 *
416 * @version 2.2.0
417 * @since 1.0.0
418 */
419 function settings_page() {
420 wp_enqueue_style( 'cookiebot-consent-mapping-table', plugins_url( 'css/consent_mapping_table.css', __FILE__ ), array(), '3.5.0' );
421
422 /* Check if multisite */
423 if($is_ms = is_multisite()) {
424 //Receive settings from multisite - this might change the way we render the form
425 $network_cbid = get_site_option('cookiebot-cbid','');
426 $network_scrip_tag_uc_attr = get_site_option('cookiebot-script-tag-uc-attribute','custom');
427 $network_scrip_tag_cd_attr = get_site_option('cookiebot-script-tag-cd-attribute','custom');
428 $network_cookie_blocking_mode = get_site_option('cookiebot-cookie-blocking-mode','manual');
429 }
430 ?>
431 <div class="wrap">
432 <h1><?php _e('Cookiebot Settings','cookiebot'); ?></h1>
433 <a href="https://www.cookiebot.com">
434 <img src="<?php echo plugins_url( 'cookiebot-logo.png', __FILE__ ); ?>" style="float:right;margin-left:1em;">
435 </a>
436 <p>
437 <?php _e('Cookiebot enables your website to comply with current legislation in the EU on the use of cookies for user tracking and profiling. The EU ePrivacy Directive requires prior, informed consent of your site users, while the <a href="https://www.cookiebot.com/goto/gdpr" target="_blank">General Data Protection Regulation (GDPR)</a> requires you to document each consent. At the same time you must be able to account for what user data you share with embedded third-party services on your website and where in the world the user data is sent.','cookiebot'); ?>
438 </p>
439 <form method="post" action="options.php">
440 <?php settings_fields( 'cookiebot' ); ?>
441 <?php do_settings_sections( 'cookiebot' ); ?>
442 <table class="form-table">
443 <tr valign="top">
444 <th scope="row"><?php _e('Cookiebot ID','cookiebot'); ?></th>
445 <td>
446 <input type="text" name="cookiebot-cbid" value="<?php echo esc_attr( get_option('cookiebot-cbid') ); ?>"<?php echo ($is_ms) ? ' placeholder="'.$network_cbid.'"' : ''; ?> style="width:300px" />
447 <p class="description">
448 <?php _e('Need an ID?','cookiebot'); ?>
449 <a href="https://www.cookiebot.com/goto/signup" target="_blank"><?php _e('Sign up for free on cookiebot.com','cookiebot'); ?></a>
450 </p>
451 </td>
452 </tr>
453 <tr valign="top">
454 <th scope="row">
455 <?php _e('Cookie-blocking mode','cookiebot'); ?>
456 </th>
457 <td>
458 <?php
459 $cbm = get_option('cookiebot-cookie-blocking-mode','manual');
460 if($is_ms && $network_cookie_blocking_mode != 'custom') {
461 $cbm = $network_cookie_blocking_mode;
462 }
463 ?>
464 <label>
465 <input type="radio" name="cookiebot-cookie-blocking-mode" value="auto" <?php checked('auto', $cbm, true); ?> />
466 <?php _e('Automatic','cookiebot'); ?>
467 </label>
468 &nbsp; &nbsp;
469 <label>
470 <input type="radio" name="cookiebot-cookie-blocking-mode" value="manual" <?php checked('manual',$cbm, true); ?> />
471 <?php _e('Manual','cookiebot'); ?>
472 </label>
473 <p class="description">
474 <?php _e('Automatic block cookies (except necessary) untill the user has given their consent.','cookiebot') ?>
475 <a href="https://support.cookiebot.com/hc/en-us/articles/360009063100-Automatic-Cookie-Blocking-How-does-it-work-" target="_blank">
476 <?php _e('Learn more','cookiebot'); ?>
477 </a>
478 </p>
479 <script>
480 jQuery(document).ready(function($) {
481 var cookieBlockingMode = '<?php echo $cbm; ?>';
482 $( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function() {
483 if(this.value == 'auto' && cookieBlockingMode != this.value ) {
484 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
485 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
486 }
487 if( this.value == 'manual' && cookieBlockingMode != this.value ) {
488 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 );
489 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false );
490 }
491 cookieBlockingMode = this.value;
492 });
493 if( cookieBlockingMode == 'auto' ) {
494 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
495 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
496 }
497 });
498 </script>
499 </td>
500 </tr>
501 <tr valign="top">
502 <th scope="row"><?php _e('Cookiebot Language','cookiebot'); ?></th>
503 <td>
504 <div>
505 <select name="cookiebot-language" id="cookiebot-language">
506 <?php
507 $currentLang = $this->get_language(true);
508 ?>
509 <option value=""><?php _e('Default (Autodetect)','cookiebot'); ?></option>
510 <option value="_wp"<?php echo ($currentLang == '_wp') ? ' selected' : ''; ?>><?php _e('Use Wordpress Language','cookiebot'); ?></option>
511 <?php
512 $supportedLanguages = $this->get_supported_languages();
513 foreach($supportedLanguages as $langCode=>$langName) {
514 echo '<option value="'.$langCode.'"'.(($currentLang==$langCode) ? ' selected' : '').'>'.$langName.'</option>';
515 }
516 ?>
517 </select>
518 </div>
519 <div class="notice inline notice-warning notice-alt cookiebot-notice" style="padding:12px;font-size:13px;display:inline-block;">
520 <div style="<?php echo ($currentLang=='') ? 'display:none;' : '' ?>" id="info_lang_specified">
521 <?php _e('You need to add the language in the Cookiebot administration tool.'); ?>
522 </div>
523 <div style="<?php echo ($currentLang=='') ? '' : 'display:none;' ?>" id="info_lang_autodetect">
524 <?php _e('You need to add all languages that you want auto-detected in the Cookiebot administration tool.'); ?> <br/>
525 <?php _e('The auto-detect checkbox needs to be enabled in the Cookiebot administration tool.'); ?><br/>
526 <?php _e('If the auto-detected language is not supported, Cookiebot will use the default language.'); ?>
527 </div>
528 <br />
529
530 <a href="#" id="show_add_language_guide"><?php _e('Show guide to add languages'); ?></a>
531 &nbsp;
532 <a href="https://support.cookiebot.com/hc/en-us/articles/360003793394-How-do-I-set-the-language-of-the-consent-banner-dialog-" target="_blank">
533 <?php _e('Read more here'); ?>
534 </a>
535
536 <div id="add_language_guide" style="display:none;">
537 <img src="<?php echo plugin_dir_url( __FILE__ ); ?>/assets/guide_add_language.gif" alt="Add language in Cookiebot administration tool" />
538 <br />
539 <a href="#" id="hide_add_language_guide"><?php _e('Hide guide'); ?></a>
540 </div>
541 </div>
542 <script>
543 jQuery(document).ready(function($) {
544 $('#show_add_language_guide').on('click',function(e) {
545 e.preventDefault();
546 $('#add_language_guide').slideDown();
547 $(this).hide();
548 });
549 $('#hide_add_language_guide').on('click',function(e) {
550 e.preventDefault();
551 $('#add_language_guide').slideUp();
552 $('#show_add_language_guide').show();
553 });
554
555 $('#cookiebot-language').on('change', function() {
556 if(this.value == '') {
557 $('#info_lang_autodetect').show();
558 $('#info_lang_specified').hide();
559 }
560 else {
561 $('#info_lang_autodetect').hide();
562 $('#info_lang_specified').show();
563 }
564 });
565 });
566 </script>
567
568 </td>
569 </tr>
570 </table>
571 <script>
572 jQuery(document).ready(function($) {
573 $('.cookiebot_fieldset_header').on('click',function(e) {
574 e.preventDefault();
575 $(this).next().slideToggle();
576 $(this).toggleClass('active');
577 });
578 });
579 </script>
580 <style type="text/css">
581 .cookiebot_fieldset_header {
582 cursor:pointer;
583 }
584 .cookiebot_fieldset_header::after {
585 content: "\f140";
586 font: normal 24px/1 dashicons;
587 position: relative;
588 top: 5px;
589 }
590 .cookiebot_fieldset_header.active::after {
591 content: "\f142";
592 }
593 </style>
594 <h3 id="advanced_settings_link" class="cookiebot_fieldset_header"><?php _e('Advanced settings', 'cookiebot'); ?></h3>
595 <div id="advanced_settings" style="display:none;">
596 <table class="form-table">
597 <tr valign="top" id="cookiebot-setting-async">
598 <th scope="row">
599 <?php _e('Add async or defer attribute','cookiebot'); ?>
600 <br /><?php _e('Consent banner script tag'); ?>
601 </th>
602 <td>
603 <?php
604 $cv = get_option('cookiebot-script-tag-uc-attribute','async');
605 $disabled = false;
606 if($is_ms && $network_scrip_tag_uc_attr != 'custom') {
607 $disabled = true;
608 $cv = $network_scrip_tag_uc_attr;
609 }
610 ?>
611 <label>
612 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="" <?php checked('', $cv, true); ?> />
613 <i>None</i>
614 </label>
615 &nbsp; &nbsp;
616 <label>
617 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="async" <?php checked('async',$cv, true); ?> />
618 async
619 </label>
620 &nbsp; &nbsp;
621 <label>
622 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="defer" <?php checked('defer',$cv, true); ?> />
623 defer
624 </label>
625 <p class="description">
626 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
627 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: async','cookiebot') ?>
628 </p>
629 </td>
630 </tr>
631 <tr valign="top">
632 <th scope="row">
633 <?php _e('Add async or defer attribute','cookiebot'); ?>
634 <br /><?php _e('Cookie declaration script tag'); ?>
635 </th>
636 <td>
637 <?php
638 $cv = get_option('cookiebot-script-tag-cd-attribute','async');
639 $disabled = false;
640 if($is_ms && $network_scrip_tag_cd_attr != 'custom') {
641 $disabled = true;
642 $cv = $network_scrip_tag_cd_attr;
643 }
644 ?>
645 <label>
646 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="" <?php checked('', $cv, true); ?> />
647 <i>None</i>
648 </label>
649 &nbsp; &nbsp;
650 <label>
651 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="async" <?php checked('async',$cv, true); ?> />
652 async
653 </label>
654 &nbsp; &nbsp;
655 <label>
656 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="defer" <?php checked('defer',$cv, true); ?> />
657 defer
658 </label>
659 <p class="description">
660 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
661 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: async','cookiebot') ?>
662 </p>
663 </td>
664 </tr>
665 <?php
666 if(!is_multisite()) {
667 ?>
668 <tr valign="top">
669 <th scope="row"><?php _e('Auto-update Cookiebot','cookiebot'); ?></th>
670 <td>
671 <input type="checkbox" name="cookiebot-autoupdate" value="1" <?php checked(1,get_option('cookiebot-autoupdate',false), true); ?> />
672 <p class="description">
673 <?php _e('Automatic update your Cookiebot plugin when new releases becomes available.','cookiebot') ?>
674 </p>
675 </td>
676 </tr>
677 <?php
678 }
679 ?>
680 <tr valign="top" id="cookiebot-setting-hide-popup">
681 <th scope="row"><?php _e('Hide Cookie Popup','cookiebot'); ?></th>
682 <td>
683 <?php
684 $disabled = false;
685 if($is_ms && get_site_option('cookiebot-nooutput',false)) {
686 $disabled = true;
687 echo '<input type="checkbox" checked disabled />';
688 }
689 else {
690 ?>
691 <input type="checkbox" name="cookiebot-nooutput" value="1" <?php checked(1,get_option('cookiebot-nooutput',false), true); ?> />
692 <?php
693 }
694 ?>
695 <p class="description">
696 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
697 <b><?php _e('This checkbox will remove the cookie consent banner from your website. The <i>[cookie_declaration]</i> shortcode will still be available.','cookiebot') ?></b><br />
698 <?php _e('If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.','cookiebot') ?><br />
699 <?php _e('<a href="https://support.cookiebot.com/hc/en-us/articles/360003793854-Google-Tag-Manager-deployment" target="_blank">See a detailed guide here</a>','cookiebot') ?>
700 </p>
701 </td>
702 </tr>
703 <tr valign="top">
704 <th scope="row"><?php _e('Disable Cookiebot in WP Admin','cookiebot'); ?></th>
705 <td>
706 <?php
707 $disabled = false;
708 if($is_ms && get_site_option('cookiebot-nooutput-admin',false)) {
709 echo '<input type="checkbox" checked disabled />';
710 $disabled = true;
711 }
712 else {
713 ?>
714 <input type="checkbox" name="cookiebot-nooutput-admin" value="1" <?php checked(1,get_option('cookiebot-nooutput-admin',false), true); ?> />
715 <?php
716 }
717 ?>
718 <p class="description">
719 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
720 <b><?php _e('This checkbox will disable Cookiebot in the Wordpress Admin area.','cookiebot') ?></b>
721 </p>
722 </td>
723 </tr>
724 </table>
725 </div>
726 <?php if($this->is_wp_consent_api_active()) { ?>
727 <h3 id="consent_level_api_settings" class="cookiebot_fieldset_header"><?php _e('Consent Level API Settings', 'cookiebot'); ?></h3>
728 <div id="consent_level_api_settings" style="display:none;">
729 <p><?php _e('WP Consent Level API and Cookiebot categorise cookies a bit different. The default settings should fit mosts needs - but if you need to change the mapping you are able to do it below.','cookiebot'); ?></p>
730
731 <?php
732 $mDefault = $this->get_default_wp_consent_api_mapping();
733
734 $m = $this->get_wp_consent_api_mapping();
735
736 $consentTypes = ['preferences', 'statistics', 'marketing'];
737 $states = array_reduce($consentTypes, function ($t, $v) {
738 $newt = [];
739 if (empty($t)) {
740 $newt = [
741 [$v => true],
742 [$v => false],
743 ];
744 } else {
745 foreach ($t as $item) {
746 $newt[] = array_merge($item, [$v => true]);
747 $newt[] = array_merge($item, [$v => false]);
748 }
749 }
750
751 return $newt;
752 }, []);
753
754 ?>
755
756
757 <table class="widefat striped consent_mapping_table">
758 <thead>
759 <tr>
760 <th><?php _e('Cookiebot categories','cookiebot'); ?></th>
761 <th class="consent_mapping"><?php _e('WP Consent Level categories','cookiebot'); ?></th>
762 </tr>
763 </thead>
764 <?php
765 foreach($states as $state) {
766
767 $key = [];
768 $key[] = 'n=1';
769 $key[] = 'p='.($state['preferences'] ? '1' : '0');
770 $key[] = 's='.($state['statistics'] ? '1' : '0');
771 $key[] = 'm='.($state['marketing'] ? '1' : '0');
772 $key = implode(';',$key);
773 ?>
774 <tr valign="top">
775 <td>
776 <div class="cb_consent">
777 <span class="forceconsent">Necessary</span>
778 <span class="<?php echo ($state['preferences'] ? 'consent' : 'noconsent'); ?>"><?php _e('Preferences','cookiebot'); ?></span>
779 <span class="<?php echo ($state['statistics'] ? 'consent' : 'noconsent'); ?>"><?php _e('Statistics','cookiebot'); ?></span>
780 <span class="<?php echo ($state['marketing'] ? 'consent' : 'noconsent'); ?>"><?php _e('Marketing','cookiebot'); ?></span>
781 </div>
782 </td>
783 <td>
784 <div class="consent_mapping">
785 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo $key; ?>][functional]" data-default-value="1" value="1" checked disabled> Functional </label>
786 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo $key; ?>][preferences]" data-default-value="<?php echo $mDefault[$key]['preferences']; ?>" value="1" <?php if($m[$key]['preferences']) { echo 'checked'; } ?>> <?php _e('Preferences','cookiebot'); ?> </label>
787 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo $key; ?>][statistics]" data-default-value="<?php echo $mDefault[$key]['statistics']; ?>" value="1" <?php if($m[$key]['statistics']) { echo 'checked'; } ?>> <?php _e('Statistics','cookiebot'); ?> </label>
788 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo $key; ?>][statistics-anonymous]" data-default-value="<?php echo $mDefault[$key]['statistics-anonymous']; ?>" value="1" <?php if($m[$key]['statistics-anonymous']) { echo 'checked'; } ?>> <?php _e('Statistics Anonymous','cookiebot'); ?></label>
789 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo $key; ?>][marketing]" data-default-value="<?php echo $mDefault[$key]['marketing']; ?>" value="1" <?php if($m[$key]['marketing']) { echo 'checked'; } ?>> <?php _e('Marketing','cookiebot'); ?></label>
790 </div>
791 </td>
792 </tr>
793 <?php
794 }
795 ?>
796 <tfoot>
797 <tr>
798 <td colspan="2" style="text-align:right;"><button class="button" onclick="return resetConsentMapping();"><?php _e('Reset to default mapping','cookiebot'); ?></button></td>
799 </tr>
800 </tfoot>
801 </table>
802 <script>
803 function resetConsentMapping() {
804 if(confirm('Are you sure you want to reset to default consent mapping?')) {
805 jQuery('.consent_mapping_table input[type=checkbox]').each(function () {
806 if(!this.disabled) {
807 this.checked = (jQuery(this).data('default-value') == '1') ? true : false;
808 }
809 });
810 }
811 return false;
812 }
813 </script>
814 </div>
815 <?php } ?>
816 <?php submit_button(); ?>
817 </form>
818 </div>
819 <?php
820 }
821
822 /**
823 * Cookiebot_WP Cookiebot network setting page
824 *
825 * @version 2.2.0
826 * @since 2.2.0
827 */
828 function network_settings_page() {
829 ?>
830 <div class="wrap">
831 <h1><?php _e('Cookiebot Network Settings','cookiebot'); ?></h1>
832 <a href="https://www.cookiebot.com">
833 <img src="<?php echo plugins_url( 'cookiebot-logo.png', __FILE__ ); ?>" style="float:right;margin-left:1em;">
834 </a>
835 <p>
836 <?php _e('Cookiebot enables your website to comply with current legislation in the EU on the use of cookies for user tracking and profiling. The EU ePrivacy Directive requires prior, informed consent of your site users, while the <a href="https://www.cookiebot.com/goto/gdpr" target="_blank">General Data Protection Regulation (GDPR)</a> requires you to document each consent. At the same time you must be able to account for what user data you share with embedded third-party services on your website and where in the world the user data is sent.','cookiebot'); ?>
837 </p>
838 <p>
839 <b><big style="color:red;"><?php _e('The settings below is network wide settings. See notes below each field.','cookiebot'); ?></big></b>
840 </p>
841 <form method="post" action="edit.php?action=cookiebot_network_settings">
842 <?php wp_nonce_field( 'cookiebot-network-settings' ); ?>
843 <table class="form-table">
844 <tr valign="top">
845 <th scope="row"><?php _e('Network Cookiebot ID','cookiebot'); ?></th>
846 <td>
847 <input type="text" name="cookiebot-cbid" value="<?php echo esc_attr( get_site_option('cookiebot-cbid','') ); ?>" style="width:300px" />
848 <p class="description">
849 <b><?php _e('If added this will be the default Cookiebot ID for all subsites. Subsites are able to override the Cookiebot ID.','cookiebot'); ?></b>
850 <br />
851 <?php _e('Need an ID?','cookiebot'); ?>
852 <a href="https://www.cookiebot.com/goto/signup" target="_blank"><?php _e('Sign up for free on cookiebot.com','cookiebot'); ?></a>
853 </p>
854 </td>
855 </tr>
856 <tr valign="top">
857 <th scope="row">
858 <?php _e('Cookie-blocking mode','cookiebot'); ?>
859 </th>
860 <td>
861 <?php
862 $cbm = get_site_option('cookiebot-cookie-blocking-mode','manual');
863 ?>
864 <label>
865 <input type="radio" name="cookiebot-cookie-blocking-mode" value="auto" <?php checked('auto', $cbm, true); ?> />
866 <?php _e('Automatic','cookiebot'); ?>
867 </label>
868 &nbsp; &nbsp;
869 <label>
870 <input type="radio" name="cookiebot-cookie-blocking-mode" value="manual" <?php checked('manual',$cbm, true); ?> />
871 <?php _e('Manual','cookiebot'); ?>
872 </label>
873 <p class="description">
874 <?php _e('Should Cookiebot automatic block cookies by tagging known tags.','cookiebot') ?>
875 </p>
876 </td>
877 </tr>
878 <script>
879 jQuery(document).ready(function($) {
880 var cookieBlockingMode = '<?php echo $cbm; ?>';
881 $( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function() {
882 if(this.value == 'auto' && cookieBlockingMode != this.value ) {
883 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
884 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
885 }
886 if( this.value == 'manual' && cookieBlockingMode != this.value ) {
887 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 );
888 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false );
889 }
890 cookieBlockingMode = this.value;
891 });
892 if( cookieBlockingMode == 'auto' ) {
893 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
894 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
895 }
896 });
897 </script>
898 <tr valign="top" id="cookiebot-setting-async">
899 <th scope="row">
900 <?php _e('Add async or defer attribute','cookiebot'); ?>
901 <br /><?php _e('Consent banner script tag'); ?>
902 </th>
903 <td>
904 <?php
905 $cv = get_site_option('cookiebot-script-tag-uc-attribute','custom');
906 ?>
907 <label>
908 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="" <?php checked('', $cv, true); ?> />
909 <i><?php _e('None','cookiebot'); ?></i>
910 </label>
911 &nbsp; &nbsp;
912 <label>
913 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="async" <?php checked('async',$cv, true); ?> />
914 async
915 </label>
916 &nbsp; &nbsp;
917 <label>
918 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="defer" <?php checked('defer',$cv, true); ?> />
919 defer
920 </label>
921 &nbsp; &nbsp;
922 <label>
923 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="custom" <?php checked('custom',$cv, true); ?> />
924 <i><?php _e('Choose per subsite','cookiebot'); ?></i>
925 </label>
926 <p class="description">
927 <b><?php _e('Setting will apply for all subsites. Subsites will not be able to override.','cookiebot'); ?></b><br />
928 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite','cookiebot') ?>
929 </p>
930 </td>
931 </tr>
932 <tr valign="top">
933 <th scope="row">
934 <?php _e('Add async or defer attribute','cookiebot'); ?>
935 <br /><?php _e('Cookie declaration script tag','cookiebot'); ?>
936 </th>
937 <td>
938 <?php
939 $cv = get_site_option('cookiebot-script-tag-cd-attribute','custom');
940 ?>
941 <label>
942 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="" <?php checked('', $cv, true); ?> />
943 <i><?php _e('None','cookiebot'); ?></i>
944 </label>
945 &nbsp; &nbsp;
946 <label>
947 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="async" <?php checked('async',$cv, true); ?> />
948 async
949 </label>
950 &nbsp; &nbsp;
951 <label>
952 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="defer" <?php checked('defer',$cv, true); ?> />
953 defer
954 </label>
955 &nbsp; &nbsp;
956 <label>
957 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="custom" <?php checked('custom',$cv, true); ?> />
958 <i><?php _e('Choose per subsite','cookiebot'); ?></i>
959 </label>
960 <p class="description">
961 <b><?php _e('Setting will apply for all subsites. Subsites will not be able to override.','cookiebot'); ?></b><br />
962 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite','cookiebot') ?>
963 </p>
964 </td>
965 </tr>
966 <tr valign="top">
967 <th scope="row"><?php _e('Auto-update Cookiebot','cookiebot'); ?></th>
968 <td>
969 <input type="checkbox" name="cookiebot-autoupdate" value="1" <?php checked(1,get_site_option('cookiebot-autoupdate',false), true); ?> />
970 <p class="description">
971 <?php _e('Automatic update your Cookiebot plugin when new releases becomes available.','cookiebot') ?>
972 </p>
973 </td>
974 </tr>
975 <tr valign="top" id="cookiebot-setting-hide-popup">
976 <th scope="row"><?php _e('Hide Cookie Popup','cookiebot'); ?></th>
977 <td>
978 <input type="checkbox" name="cookiebot-nooutput" value="1" <?php checked(1,get_site_option('cookiebot-nooutput',false), true); ?> />
979 <p class="description">
980 <b><?php _e('Remove the cookie consent banner from all subsites. This cannot be changed by subsites. The <i>[cookie_declaration]</i> shortcode will still be available.','cookiebot') ?></b><br />
981 <?php _e('If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.','cookiebot') ?><br />
982 <?php _e('<a href="https://support.cookiebot.com/hc/en-us/articles/360003793854-Google-Tag-Manager-deployment" target="_blank">See a detailed guide here</a>','cookiebot') ?>
983 </p>
984 </td>
985 </tr>
986 <tr valign="top">
987 <th scope="row"><?php _e('Hide Cookie Popup in WP Admin','cookiebot'); ?></th>
988 <td>
989 <input type="checkbox" name="cookiebot-nooutput-admin" value="1" <?php checked(1,get_site_option('cookiebot-nooutput-admin',false), true); ?> />
990 <p class="description">
991 <b><?php _e('Remove the cookie consent banner the Wordpress Admin area for all subsites. This cannot be changed by subsites.','cookiebot') ?></b>
992 </p>
993 </td>
994 </tr>
995 </table>
996 <?php submit_button(); ?>
997 </form>
998 </div>
999 <?php
1000 }
1001
1002
1003 /**
1004 * Cookiebot_WP Cookiebot save network settings
1005 *
1006 * @version 2.2.0
1007 * @since 2.2.0
1008 */
1009 function network_settings_save() {
1010 check_admin_referer( 'cookiebot-network-settings' );
1011
1012 update_site_option('cookiebot-cbid', $_POST['cookiebot-cbid'] );
1013 update_site_option('cookiebot-script-tag-uc-attribute', $_POST['cookiebot-script-tag-uc-attribute'] );
1014 update_site_option('cookiebot-script-tag-cd-attribute', $_POST['cookiebot-script-tag-cd-attribute'] );
1015 update_site_option('cookiebot-autoupdate', $_POST['cookiebot-autoupdate'] );
1016 update_site_option('cookiebot-nooutput', $_POST['cookiebot-nooutput'] );
1017 update_site_option('cookiebot-nooutput-admin', $_POST['cookiebot-nooutput-admin'] );
1018 update_site_option('cookiebot-cookie-blocking-mode', $_POST['cookiebot-cookie-blocking-mode'] );
1019
1020
1021 wp_redirect( add_query_arg( array(
1022 'page' => 'cookiebot_network',
1023 'updated' => true ), network_admin_url('admin.php')
1024 ));
1025 exit;
1026 }
1027
1028 /**
1029 * Cookiebot_WP Cookiebot support page
1030 *
1031 * @version 2.2.0
1032 * @since 2.0.0
1033 */
1034 function support_page() {
1035 ?>
1036 <div class="wrap">
1037 <h1><?php _e('Support','cookiebot'); ?></h1>
1038 <h2><?php _e('How to find my Cookiebot ID','cookiebot'); ?></h2>
1039 <p>
1040 <ol>
1041 <li><?php _e('Log in to your <a href="https://www.cookiebot.com/goto/account" target="_blank">Cookiebot account</a>.','cookiebot'); ?></li>
1042 <li><?php _e('Go to <b>Manage</b> > <b>Settings</b> and add setup your Cookiebot','cookiebot'); ?></li>
1043 <li><?php _e('Go to the <b>"Your scripts"</b> tab','cookiebot'); ?></li>
1044 <li><?php _e('Copy the value inside the data-cid parameter - eg.: abcdef12-3456-7890-abcd-ef1234567890','cookiebot'); ?></li>
1045 <li><?php _e('Add <b>[cookie_declaration]</b> shortcode to a page to show the declation','cookiebot'); ?></li>
1046 <li><?php _e('Remember to change your scripts as descripted below','cookiebot'); ?></li>
1047 </ol>
1048 </p>
1049 <h2><?php _e('Add the Cookie Declaration to your website'); ?></h2>
1050 <p>
1051 <?php _e('Use the shortcode <b>[cookie_declaration]</b> to add the cookie declaration a page or post. The cookie declaration will always show the latest version from Cookiebot.','cookiebot'); ?>
1052 <br />
1053 <?php _e('If you need to force language of the cookie declaration, you can add the <i>lang</i> attribute. Eg. <b>[cookie_declaration lang="de"]</b>.','cookiebot'); ?>
1054 </p>
1055 <p>
1056 <a href="https://www.youtube.com/watch?v=OCXz2bt4H_w" target="_blank" class="button"><?php _e('Watch video demonstration','cookiebot'); ?></a>
1057 </p>
1058 <h2><?php _e('Update your script tags','cookiebot'); ?></h2>
1059 <p>
1060 <?php _e('To enable prior consent, apply the attribute "data-cookieconsent" to cookie-setting script tags on your website. Set the comma-separated value to one or more of the cookie categories "preferences", "statistics" and "marketing" in accordance with the types of cookies being set by each script. Finally change the attribute "type" from "text/javascript" to "text/plain". Example on modifying an existing Google Analytics Universal script tag.','cookiebot'); ?>
1061 </p>
1062 <code>
1063 <?php
1064 echo htmlentities("<script type=\"text/plain\" data-cookieconsent=\"statistics\">").'<br />';
1065 echo htmlentities("(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');").'<br />';
1066 echo htmlentities("ga('create', 'UA-00000000-0', 'auto');").'<br />';
1067 echo htmlentities("ga('send', 'pageview');").'<br />';
1068 echo htmlentities("</script>").'<br />';
1069 ?>
1070 </code>
1071 <p>
1072 <a href="https://www.youtube.com/watch?v=MeHycvV2QCQ" target="_blank" class="button"><?php _e('Watch video demonstration','cookiebot'); ?></a>
1073 </p>
1074
1075 <h2><?php _e('Helper function to update your scripts','cookiebot'); ?></h2>
1076 <p>
1077 <?php _e('You are able to update your scripts yourself. However, Cookiebot also offers a small helper function that makes the work easier.','cookiebot'); ?>
1078 <br />
1079 <?php _e('Update your script tags this way:','cookiebot'); ?>
1080 </p>
1081 <?php
1082 printf(
1083 __('%s to %s'),
1084 '<code>'.htmlentities('<script type="text/javascript">').'</code>',
1085 '<code>'.htmlentities('<script<?php echo cookiebot_assist(\'marketing\') ?>>').'</code>'
1086 );
1087 ?>
1088 </div>
1089 <?php
1090 }
1091
1092 /**
1093 * Cookiebot_WP Cookiebot IAB page
1094 *
1095 * @version 2.0.0
1096 * @since 2.0.0
1097 */
1098 function iab_page() {
1099 ?>
1100 <div class="wrap">
1101 <h1><?php _e('IAB','cookiebot'); ?></h1>
1102
1103 <p>For more details about Cookiebot's IAB integration, see <a href="https://support.cookiebot.com/hc/en-us/articles/360007652694-Cookiebot-and-the-IAB-Consent-Framework" target="_blank">article about cookiebot and the IAB consent framework</a></p>
1104
1105 <form method="post" action="options.php">
1106 <?php settings_fields( 'cookiebot-iab' ); ?>
1107 <?php do_settings_sections( 'cookiebot-iab' ); ?>
1108
1109 <label>Enable IAB integration</label>
1110 <input type="checkbox" name="cookiebot-iab" value="1" <?php checked(1,get_option('cookiebot-iab'), true); ?>>
1111
1112 <?php submit_button(); ?>
1113 </form>
1114 </div>
1115 <?php
1116 }
1117
1118 /**
1119 * Cookiebot_WP Debug Page
1120 *
1121 * @version 3.6.0
1122 * @since 3.6.0
1123 */
1124
1125 function debug_page() {
1126 global $wpdb;
1127
1128 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1129 $plugins = get_plugins();
1130 $active_plugins = get_option( 'active_plugins' );
1131
1132
1133 //$foo = new cookiebot_addons\lib\Settings_Service;
1134 //$addons = $foo->get_active_addons();
1135
1136 $debugStr = "";
1137 $debugStr.= "##### Debug Information for ".get_site_url()." generated at ".date("c")." #####\n\n";
1138 $debugStr.= "Wordpress Version: ".get_bloginfo('version')."\n";
1139 $debugStr.= "Wordpress Language: ".get_bloginfo('language')."\n";
1140 $debugStr.= "PHP Version: ".phpversion()."\n";
1141 $debugStr.= "MySQL Version: ".$wpdb->db_version()."\n";
1142 $debugStr.= "\n--- Cookiebot Information ---\n";
1143 $debugStr.= "Plugin Version: ".$this->version."\n";
1144 $debugStr.= "Cookiebot ID: ".$this->get_cbid()."\n";
1145 $debugStr.= "Blocking mode: ".get_option('cookiebot-cookie-blocking-mode')."\n";
1146 $debugStr.= "Language: ".get_option('cookiebot-language')."\n";
1147 $debugStr.= "IAB: ".(get_option('cookiebot-iab') == '1' ? 'Enabled' : 'Not enabled')."\n";
1148 $debugStr.= "Add async/defer to banner tag: ".(get_option('cookiebot-script-tag-uc-attribute') != '' ? get_option('cookiebot-script-tag-uc-attribute') : 'None')."\n";
1149 $debugStr.= "Add async/defer to declaration tag: ".(get_option('cookiebot-script-tag-cd-attribute') != '' ? get_option('cookiebot-script-tag-cd-attribute') : 'None')."\n";
1150 $debugStr.= "Auto update: ".(get_option('cookiebot-autoupdate') == '1' ? 'Enabled' : 'Not enabled')."\n";
1151 $debugStr.= "Hide Cookie Popup: ".(get_option('cookiebot-nooutput') == '1' ? 'Yes' : 'No')."\n";
1152 $debugStr.= "Disable Cookiebot in WP Admin: ".(get_option('cookiebot-nooutput-admin') == '1' ? 'Yes' : 'No')."\n";
1153 $debugStr.= "Banner tag: ".$this->add_js(false)."\n";
1154 $debugStr.= "Declaration tag: ".$this->show_declaration()."\n";
1155
1156 if($this->is_wp_consent_api_active()) {
1157 $debugStr.= "\n--- WP Consent Level API Mapping ---\n";
1158 $debugStr .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous'."\n";
1159 $m = $this->get_wp_consent_api_mapping();
1160 foreach($m as $k=>$v) {
1161 $cb = array();
1162
1163 $debugStr .= strtoupper( str_replace(';', ', ', $k ) ) . ' => ';
1164
1165 $debugStr .= 'F=1, ';
1166 $debugStr .= 'P=' . $v['preferences'] . ', ';
1167 $debugStr .= 'M=' . $v['marketing'] . ', ';
1168 $debugStr .= 'S=' . $v['statistics'] . ', ';
1169 $debugStr .= 'SA=' . $v['statistics-anonymous'] . "\n";
1170
1171 }
1172
1173 }
1174
1175 if(class_exists('cookiebot_addons\Cookiebot_Addons')) {
1176 $ca = new cookiebot_addons\Cookiebot_Addons();
1177 $settingservice = $ca->container->get( 'Settings_Service_Interface' );
1178 $addons = $settingservice->get_active_addons();
1179 $debugStr.= "\n--- Activated Cookiebot Addons ---\n";
1180 foreach($addons as $addon) {
1181 $debugStr.= $addon->get_addon_name()." (".implode( ", ", $addon->get_cookie_types() ).")\n";
1182 }
1183 }
1184
1185 $debugStr.= "\n--- Activated Plugins ---\n";
1186 foreach($active_plugins as $p) {
1187 if($p != 'cookiebot/cookiebot.php') {
1188 $debugStr.= $plugins[$p]['Name'] . " (Version: ".$plugins[$p]['Version'].")\n";
1189 }
1190 }
1191
1192 $debugStr.= "\n##### Debug Information END #####";
1193
1194 ?>
1195 <div class="wrap">
1196 <h1><?php _e('Debug information','cookiebot'); ?></h1>
1197 <p><?php _e('The information below is for debugging purpose. If you have any issues with your Cookiebot integration, the information below is usefull for a supporter to help you the best way.'); ?></p>
1198 <p><button class="button button-primary" onclick="copyDebugInfo();"><?php _e('Copy debug information to clipboard'); ?></button></p>
1199 <textarea cols="100" rows="40" style="width:800px;max-width:100%;" id="cookiebot-debug-info" readonly><?php echo $debugStr; ?></textarea>
1200 <script>
1201 function copyDebugInfo() {
1202 var t = document.getElementById("cookiebot-debug-info");
1203 t.select();
1204 t.setSelectionRange(0, 99999);
1205 document.execCommand("copy");
1206 }
1207 </script>
1208 </div>
1209 <?php
1210 }
1211
1212 /**
1213 * Cookiebot_WP Add Cookiebot JS to <head>
1214 *
1215 * @version 3.6.0
1216 * @since 1.0.0
1217 */
1218 function add_js($printTag=true) {
1219 $cbid = $this->get_cbid();
1220 if(!empty($cbid) && !defined('COOKIEBOT_DISABLE_ON_PAGE')) {
1221 if(is_multisite() && get_site_option('cookiebot-nooutput',false)) {
1222 return; //Is multisite - and disabled output is checked as network setting
1223 }
1224 if(get_option('cookiebot-nooutput',false)) {
1225 return; //Do not show JS - output disabled
1226 }
1227
1228 if($this->get_cookie_blocking_mode() == 'auto' && $this->can_current_user_edit_theme() && $printTag !== false ) {
1229 return;
1230 }
1231
1232 $lang = $this->get_language();
1233 if(!empty($lang)) {
1234 $lang = ' data-culture="'.strtoupper($lang).'"'; //Use data-culture to define language
1235 }
1236
1237 if(!is_multisite() || get_site_option('cookiebot-script-tag-uc-attribute','custom') == 'custom') {
1238 $tagAttr = get_option('cookiebot-script-tag-uc-attribute','async');
1239 }
1240 else {
1241 $tagAttr = get_site_option('cookiebot-script-tag-uc-attribute');
1242 }
1243
1244 if($this->get_cookie_blocking_mode() == 'auto') {
1245 $tagAttr = 'data-blockingmode="auto"';
1246 }
1247
1248 $iab = ( get_option('cookiebot-iab') != false ) ? 'data-framework="IAB"' : '';
1249
1250 $tag = '<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" '.$iab.' data-cbid="'.$cbid.'"'.$lang.' type="text/javascript" '.$tagAttr.'></script>';
1251 if($printTag===false) {
1252 return $tag;
1253 }
1254 echo $tag;
1255 }
1256 }
1257
1258 /**
1259 * Returns true if an user is logged in and has an edit_themes capability
1260 *
1261 * @return bool
1262 *
1263 * @since 3.3.1
1264 * @version 3.4.1
1265 */
1266 function can_current_user_edit_theme() {
1267 if( is_user_logged_in() ) {
1268 if( current_user_can('edit_themes') ) {
1269 return true;
1270 }
1271
1272 if( current_user_can( 'edit_pages' ) ) {
1273 return true;
1274 }
1275
1276 if( current_user_can( 'edit_posts' ) ) {
1277 return true;
1278 }
1279 }
1280
1281 return false;
1282 }
1283
1284 /**
1285 * Cookiebot_WP Output declation shortcode [cookie_declaration]
1286 * Support attribute lang="LANGUAGE_CODE". Eg. lang="en".
1287 *
1288 * @version 2.2.0
1289 * @since 1.0.0
1290 */
1291 function show_declaration($atts=array()) {
1292 $cbid = $this->get_cbid();
1293 $lang = '';
1294 if(!empty($cbid)) {
1295
1296 $atts = shortcode_atts(array(
1297 'lang' => $this->get_language(),
1298 ), $atts, 'cookie_declaration'
1299 );
1300
1301 if(!empty($atts['lang'])) {
1302 $lang = ' data-culture="'.strtoupper($atts['lang']).'"'; //Use data-culture to define language
1303 }
1304
1305 if(!is_multisite() || get_site_option('cookiebot-script-tag-cd-attribute','custom') == 'custom') {
1306 $tagAttr = get_option('cookiebot-script-tag-cd-attribute','async');
1307 }
1308 else {
1309 $tagAttr = get_site_option('cookiebot-script-tag-cd-attribute');
1310 }
1311
1312 return '<script id="CookieDeclaration" src="https://consent.cookiebot.com/'.$cbid.'/cd.js"'.$lang.' type="text/javascript" '.$tagAttr.'></script>';
1313 }
1314 else {
1315 return __('Please add your Cookiebot ID to show Cookie Declarations','cookiebot');
1316 }
1317 }
1318
1319 /**
1320 * Cookiebot_WP Get cookiebot cbid
1321 *
1322 * @version 2.2.0
1323 * @since 1.0.0
1324 */
1325 public static function get_cbid() {
1326 $cbid = get_option('cookiebot-cbid');
1327 if(is_multisite() && ($network_cbid = get_site_option('cookiebot-cbid'))) {
1328 if(empty($cbid)) {
1329 return $network_cbid;
1330 }
1331 }
1332 return $cbid;
1333 }
1334
1335 /**
1336 * Cookiebot_WP Get cookie blocking mode (auto | manual)
1337 *
1338 * @version 2.2.0
1339 * @since 1.0.0
1340 */
1341 public static function get_cookie_blocking_mode() {
1342 $cbm = get_option('cookiebot-cookie-blocking-mode');
1343 if(is_multisite() && ($network_cbm = get_site_option('cookiebot-cookie-blocking-mode'))) {
1344 if(empty($cbm)) {
1345 return $network_cbm;
1346 }
1347 }
1348 if(empty($cbm)) { $cbm = 'manual'; }
1349 return $cbm;
1350 }
1351
1352
1353 /**
1354 * Cookiebot_WP Check if Cookiebot is active in admin
1355 *
1356 * @version 3.1.0
1357 * @since 3.1.0
1358 */
1359 public static function cookiebot_disabled_in_admin() {
1360 if(is_multisite() && get_site_option('cookiebot-nooutput-admin',false)) {
1361 return true;
1362 }
1363 elseif(get_option('cookiebot-nooutput-admin',false)) {
1364 return true;
1365 }
1366 return false;
1367 }
1368
1369 /**
1370 * Cookiebot_WP Get the language code for Cookiebot
1371 *
1372 * @version 1.4.0
1373 * @since 1.4.0
1374 */
1375 function get_language($onlyFromSetting=false) {
1376 // Get language set in setting page - if empty use WP language info
1377 $lang = get_option('cookiebot-language');
1378 if(!empty($lang)) {
1379 if($lang != '_wp') {
1380 return $lang;
1381 }
1382 }
1383
1384 if($onlyFromSetting) {
1385 return $lang; //We want only to get if already set
1386 }
1387
1388 //Language not set - use WP language
1389 if($lang == '_wp') {
1390 $lang = get_bloginfo('language'); //Gets language in en-US format
1391 if(!empty($lang)) {
1392 list($lang) = explode('-',$lang); //Changes format from eg. en-US to en.
1393 }
1394 }
1395 return $lang;
1396 }
1397
1398 /**
1399 * Cookiebot_WP Adding Cookiebot domain(s) to exclude list for WP Rocket minification.
1400 *
1401 * @version 1.6.1
1402 * @since 1.6.1
1403 */
1404 function wp_rocket_exclude_external_js($external_js_hosts) {
1405 $external_js_hosts[] = 'consent.cookiebot.com'; // Add cookiebot domains
1406 $external_js_hosts[] = 'consentcdn.cookiebot.com';
1407 return $external_js_hosts;
1408 }
1409
1410
1411 /**
1412 * Cookiebot_WP Check if WP Cookie Consent API is active
1413 *
1414 * @version 3.5.0
1415 * @since 3.5.0
1416 */
1417 public function is_wp_consent_api_active() {
1418 if ( class_exists( 'WP_CONSENT_API' ) ) {
1419 return true;
1420 }
1421 return false;
1422 }
1423
1424 /**
1425 * Cookiebot_WP Default consent level mappings
1426 *
1427 * @version 3.5.0
1428 * @since 3.5.0
1429 */
1430 public function get_default_wp_consent_api_mapping() {
1431 return array(
1432 'n=1;p=1;s=1;m=1' =>
1433 array('preferences'=>1,'statistics'=>1,'statistics-anonymous'=>0,'marketing'=>1),
1434 'n=1;p=1;s=1;m=0' =>
1435 array('preferences'=>1,'statistics'=>1,'statistics-anonymous'=>1,'marketing'=>0),
1436 'n=1;p=1;s=0;m=1' =>
1437 array('preferences'=>1,'statistics'=>0,'statistics-anonymous'=>0,'marketing'=>1),
1438 'n=1;p=1;s=0;m=0' =>
1439 array('preferences'=>1,'statistics'=>0,'statistics-anonymous'=>0,'marketing'=>0),
1440 'n=1;p=0;s=1;m=1' =>
1441 array('preferences'=>0,'statistics'=>1,'statistics-anonymous'=>0,'marketing'=>1),
1442 'n=1;p=0;s=1;m=0' =>
1443 array('preferences'=>0,'statistics'=>1,'statistics-anonymous'=>0,'marketing'=>0),
1444 'n=1;p=0;s=0;m=1' =>
1445 array('preferences'=>0,'statistics'=>0,'statistics-anonymous'=>0,'marketing'=>1),
1446 'n=1;p=0;s=0;m=0' =>
1447 array('preferences'=>0,'statistics'=>0,'statistics-anonymous'=>0,'marketing'=>0),
1448 );
1449
1450 }
1451
1452 /**
1453 * Cookiebot_WP Get the mapping between Consent Level API and Cookiebot
1454 * Returns array where key is the consent level api category and value
1455 * is the mapped Cookiebot category.
1456 *
1457 * @version 3.5.0
1458 * @since 3.5.0
1459 */
1460 public function get_wp_consent_api_mapping() {
1461 $mDefault = $this->get_default_wp_consent_api_mapping();
1462 $mapping = get_option( 'cookiebot-consent-mapping', $mDefault);
1463
1464 $mapping = ( '' === $mapping ) ? $mDefault : $mapping;
1465
1466 foreach($mDefault as $k=>$v) {
1467 if(!isset($mapping[$k])) {
1468 $mapping[$k] = $v;
1469 }
1470 else {
1471 foreach($v as $vck=>$vcv) {
1472 if(!isset($mapping[$k][$vck])) {
1473 $mapping[$k][$vck] = $vcv;
1474 }
1475 }
1476 }
1477 }
1478 return $mapping;
1479 }
1480
1481 /**
1482 * Cookiebot_WP Enqueue JS for integration with WP Consent Level API
1483 *
1484 * @version 3.5.0
1485 * @since 3.5.0
1486 */
1487 function cookiebot_enqueue_consent_api_scripts() {
1488 wp_register_script( 'cookiebot-wp-consent-level-api-integration', plugins_url( 'cookiebot/js/cookiebot-wp-consent-level-api-integration.js', 'cookiebot' ) );
1489 wp_enqueue_script( 'cookiebot-wp-consent-level-api-integration' );
1490 wp_localize_script( 'cookiebot-wp-consent-level-api-integration', 'cookiebot_category_mapping', $this->get_wp_consent_api_mapping() );
1491 }
1492
1493
1494 /**
1495 * Display admin notice for recommending cookiebot
1496 *
1497 * @version 2.0.5
1498 * @since 2.0.5
1499 */
1500 function cookiebot_admin_notices() {
1501 if( ! $this->cookiebot_valid_admin_recommendation() ) {
1502 return false;
1503 }
1504 $two_week_review_ignore = add_query_arg( array( 'cookiebot_admin_notice' => 'hide' ) );
1505 $two_week_review_temp = add_query_arg( array( 'cookiebot_admin_notice' => 'two_week' ) );
1506
1507 $notices = array(
1508 'title' => __('Leave A Review?', 'cookiebot'),
1509 'msg' => __('We hope you enjoy using WordPress Cookiebot! Would you consider leaving us a review on WordPress.org?', 'cookiebot'),
1510 'link' => '<li><span class="dashicons dashicons-external"></span><a href="https://wordpress.org/support/plugin/cookiebot/reviews?filter=5&rate=5#new-post" target="_blank">' . __('Sure! I\'d love to!', 'cookiebot') . '</a></li>
1511 <li><span class="dashicons dashicons-smiley"></span><a href="' . $two_week_review_ignore . '"> ' . __('I\'ve already left a review', 'cookiebot') . '</a></li>
1512 <li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __('Maybe Later', 'cookiebot') . '</a></li>
1513 <li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __('Never show again', 'cookiebot') . '</a></li>',
1514 'later_link' => $two_week_review_temp,
1515 'int' => 14
1516 );
1517
1518 echo '<div class="update-nag cookiebot-admin-notice">
1519 <div class="cookiebot-notice-logo"></div>
1520 <p class="cookiebot-notice-title">' . $notices['title'] . '</p>
1521 <p class="cookiebot-notice-body">' . $notices['msg'] . '</p>
1522 <ul class="cookiebot-notice-body wd-blue">' . $notices['link'] . '</ul>
1523 <a href="' . $notices['later_link'] . '" class="dashicons dashicons-dismiss"></a>
1524 </div>';
1525
1526 wp_enqueue_style( 'cookiebot-admin-notices', plugins_url( 'css/notice.css', __FILE__ ), array(), '2.0.4' );
1527 }
1528
1529
1530 /**
1531 * Validate if the last user action is valid for plugin recommendation
1532 *
1533 * @return bool
1534 *
1535 * @version 2.0.5
1536 * @since 2.0.5
1537 */
1538 function cookiebot_valid_admin_recommendation() {
1539 //Default - the recommendation is allowed to be visible
1540 $return = true;
1541
1542 $option = get_option('cookiebot_notice_recommend');
1543
1544 if( $option != false ) {
1545 //Never show again is clicked
1546 if( $option == 'hide' ) {
1547 $return = false;
1548 }
1549 elseif( is_numeric($option) && strtotime('now') < $option ) {
1550 //Show me after 2 weeks is clicked and the time is not valid yet
1551 $return = false;
1552 }
1553 }
1554 return $return;
1555 }
1556
1557 /**
1558 * Save the user action on cookiebot recommendation link
1559 *
1560 * @version 2.0.5
1561 * @since 2.0.5
1562 */
1563 function save_notice_link() {
1564 if( isset( $_GET['cookiebot_admin_notice'] ) ) {
1565 if( $_GET['cookiebot_admin_notice'] == 'hide' ) {
1566 update_option('cookiebot_notice_recommend', 'hide' );
1567 }
1568 else {
1569 update_option('cookiebot_notice_recommend', strtotime('+2 weeks') );
1570 }
1571 }
1572 }
1573
1574
1575
1576
1577 /**
1578 * Cookiebot_WP Fix plugin conflicts related to Cookiebot
1579 *
1580 * @version 3.2.0
1581 * @since 3.3.0
1582 */
1583 function cookiebot_fix_plugin_conflicts() {
1584 //Fix for Divi Page Builder
1585 //Disabled - using another method now (can_current_user_edit_theme())
1586 //add_action( 'wp', array( $this, '_cookiebot_plugin_conflict_divi' ), 100 );
1587
1588 //Fix for Elementor and WPBakery Page Builder Builder
1589 //Disabled - using another method now (can_current_user_edit_theme())
1590 //add_filter( 'script_loader_tag', array( $this, '_cookiebot_plugin_conflict_scripttags' ), 10, 2 );
1591 }
1592
1593 /**
1594 * Cookiebot_WP Fix Divi builder conflict when blocking mode is in auto.
1595 *
1596 * @version 3.2.0
1597 * @since 3.2.0
1598 */
1599 function _cookiebot_plugin_conflict_divi() {
1600 if ( defined( 'ET_FB_ENABLED' ) ) {
1601 if ( ET_FB_ENABLED &&
1602 $this->cookiebot_disabled_in_admin() &&
1603 $this->get_cookie_blocking_mode() == 'auto' ) {
1604
1605 define('COOKIEBOT_DISABLE_ON_PAGE',true); //Disable Cookiebot on the current page
1606
1607 }
1608 }
1609 }
1610
1611 /**
1612 * Cookiebot_WP Fix plugin conflicts with page builders - whitelist JS files in automode
1613 *
1614 * @version 3.2.0
1615 * @since 3.3.0
1616 */
1617 function _cookiebot_plugin_conflict_scripttags( $tag, $handle ) {
1618
1619 //Check if Elementor Page Builder active
1620 if( defined( 'ELEMENTOR_VERSION' ) ) {
1621 if( in_array( $handle, [
1622 'jquery-core',
1623 'elementor-frontend-modules',
1624 'elementor-frontend',
1625 'wp-tinymce' ,
1626 'underscore',
1627 'backbone',
1628 'backbone-marionette',
1629 'backbone-radio',
1630 'elementor-common-modules',
1631 'elementor-dialog',
1632 'elementor-common',
1633 ] ) ) {
1634 $tag = str_replace( '<script ', '<script data-cookieconsent="ignore" ', $tag );
1635 }
1636 }
1637
1638 //Check if WPBakery Page Builder active
1639 if ( defined( 'WPB_VC_VERSION' ) ) {
1640 if( in_array( $handle, [
1641 'jquery-core',
1642 'jquery-ui-core',
1643 'jquery-ui-sortable',
1644 'jquery-ui-mouse',
1645 'jquery-ui-widget',
1646 'vc_editors-templates-preview-js',
1647 'vc-frontend-editor-min-js',
1648 'vc_inline_iframe_js',
1649 'wpb_composer_front_js',
1650 ] ) ) {
1651 $tag = str_replace( '<script ', '<script data-cookieconsent="ignore" ', $tag );
1652 }
1653 }
1654
1655 return $tag;
1656 }
1657
1658 }
1659 endif;
1660
1661
1662 /**
1663 * Helper function to manipulate script tags
1664 *
1665 * @version 1.6
1666 * @since 1.0
1667 * @return string
1668 */
1669 function cookiebot_assist($type='statistics') {
1670 //change to array
1671 if(!is_array($type)) { $type = array($type); }
1672
1673 foreach($type as $tk=>$tv) {
1674 if(!in_array($tv,array('marketing','statistics','preferences'))) {
1675 unset($type[$tk]);
1676 }
1677 }
1678 if(sizeof($type) > 0) {
1679 return ' type="text/plain" data-cookieconsent="'.implode(',',$type).'"';
1680 }
1681 return '';
1682 }
1683
1684
1685 /**
1686 * Helper function to check if cookiebot is active.
1687 * Useful for other plugins adding support for Cookiebot.
1688 *
1689 * @version 2.2.2
1690 * @since 1.2
1691 * @return string
1692 */
1693 function cookiebot_active() {
1694 $cbid = Cookiebot_WP::get_cbid();
1695 if(!empty($cbid)) {
1696 return true;
1697 }
1698 return false;
1699 }
1700
1701
1702 if(!function_exists('cookiebot')) {
1703 /**
1704 * Returns the main instance of Cookiebot_WO to prevent the need to use globals.
1705 *
1706 * @version 1.0.0
1707 * @since 1.0.0
1708 * @return Cookiebot_WP
1709 */
1710 function cookiebot() {
1711 return Cookiebot_WP::instance();
1712 }
1713 }
1714
1715 cookiebot();
1716