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