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