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