PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 2.4.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v2.4.2
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 7 years ago assets 7 years ago css 7 years ago documentation 7 years ago langs 8 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 7 years ago phpunit.xml 7 years ago readme.txt 7 years ago
cookiebot.php
1130 lines
1 <?php
2 /*
3 Plugin Name: Cookiebot | GDPR Compliant Cookie Consent and Notice
4 Plugin URI: https://cookiebot.com/
5 Description: Cookiebot is a fully GDPR & ePrivacy compliant cookie consent solution supporting prior consent, cookie declaration, and documentation of consents. Easy to install, implement and configure.
6 Author: Cybot A/S
7 Version: 2.4.2
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 = '2.4.2';
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
62 /**
63 * Cookiebot_WP Installation actions
64 *
65 * @version 2.1.4
66 * @since 2.1.4
67 * @accces public
68 */
69 function activation() {
70 //Delay display of recommendation notice in 3 days if not activated ealier
71 if(get_option('cookiebot_notice_recommend',false) === false) {
72 //Not set yet - this must be first activation - delay in 3 days
73 update_option('cookiebot_notice_recommend', strtotime('+3 days'));
74 }
75 }
76
77 /**
78 * Cookiebot_WP Init Cookiebot.
79 *
80 * @version 2.2.0
81 * @since 1.6.2
82 * @access public
83 */
84 function cookiebot_init() {
85 /* Load Cookiebot Addons Framework */
86 $dismissAddons = false;
87 if(defined('CAF_DIR')) {
88 $dismissAddons = true;
89 /*add_action('admin_notices', function() {
90 ?>
91 <div class="notice notice-warning">
92 <p>
93 <?php _e( 'You have Cookiebot Addons installed.', 'cookiebot' ); ?><br />
94 <?php _e( 'In this and future releases of Cookiebot all available Addons are bundled directly with the Cookiebot plugin.', 'cookiebot' ); ?><br />
95 <?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' ); ?>
96 </p>
97 </div>
98 <?php
99 });*/
100 }
101 else {
102 if( (!defined('COOKIEBOT_ADDONS_STANDALONE') || COOKIEBOT_ADDONS_STANDALONE != true || !defined('COOKIE_ADDONS_LOADED')) && $dismissAddons !== true ) {
103 //Make sure we got a PHP version that works
104 if(version_compare(PHP_VERSION, '5.4.0', '>=')) {
105 define('COOKIEBOT_URL', plugin_dir_url( __FILE__ ));
106 include_once('addons/cookiebot-addons-init.php');
107 }
108 else {
109 define('COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION',true);
110 }
111 }
112 else {
113 add_action('admin_notices', function() {
114 ?>
115 <div class="notice notice-warning">
116 <p>
117 <?php _e( 'You are using Cookiebot Addons Standalone.', 'cookiebot' ); ?>
118 </p>
119 </div>
120 <?php
121 });
122 }
123 }
124 if(is_admin()) {
125
126 //Adding menu to WP admin
127 add_action('admin_menu', array($this,'add_menu'),1);
128
129 if(is_multisite()) {
130 add_action('network_admin_menu', array($this,'add_network_menu'),1);
131 add_action('network_admin_edit_cookiebot_network_settings', array($this,'network_settings_save'));
132 }
133
134 //Register settings
135 add_action('admin_init', array($this,'register_cookiebot_settings'));
136
137 //Adding dashboard widgets
138 add_action('wp_dashboard_setup', array($this,'add_dashboard_widgets'));
139
140 add_action('admin_notices', array( $this, 'cookiebot_admin_notices' ) );
141 add_action('admin_init', array($this,'save_notice_link'));
142
143 //Check if we should show cookie consent banner on admin pages
144 $addJSAdmin = true;
145 if(is_multisite() && get_site_option('cookiebot-nooutput-admin',false)) {
146 $addJSAdmin = false;
147 }
148 elseif(get_option('cookiebot-nooutput-admin',false)) {
149 $addJSAdmin = false;
150 }
151 if($addJSAdmin) {
152 //adding cookie banner in admin area too
153 add_action('admin_head', array($this,'add_js'));
154 }
155 }
156
157
158 // Set up localisation
159 load_plugin_textdomain('cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
160
161 //add JS
162 add_action('wp_head', array($this,'add_js'));
163 add_shortcode('cookie_declaration', array($this,'show_declaration'));
164
165 //Add filter if WP rocket is enabled
166 if(defined('WP_ROCKET_VERSION')) {
167 add_filter('rocket_minify_excluded_external_js', array($this,'wp_rocket_exclude_external_js'));
168 }
169
170 //Automatic update plugin
171 if(is_admin() || (defined('DOING_CRON') && DOING_CRON)) {
172 add_filter('auto_update_plugin', array($this,'automatic_updates'), 10, 2);
173 }
174 }
175
176 /**
177 * Cookiebot_WP Load text domain
178 *
179 * @version 2.0.0
180 * @since 2.0.0
181 */
182 function load_textdomain() {
183 load_plugin_textdomain( 'cookiebot', false, basename( dirname( __FILE__ ) ) . '/langs' );
184 }
185
186 /**
187 * Cookiebot_WP Add dashboard widgets to admin
188 *
189 * @version 1.0.0
190 * @since 1.0.0
191 */
192
193 function add_dashboard_widgets() {
194 wp_add_dashboard_widget('cookiebot_status', __('Cookiebot Status','cookiebot'), array($this,'dashboard_widget_status'));
195 }
196
197 /**
198 * Cookiebot_WP Output Dashboard Status Widget
199 *
200 * @version 1.0.0
201 * @since 1.0.0
202 */
203 function dashboard_widget_status() {
204 $cbid = $this->get_cbid();
205 if(empty($cbid)) {
206 echo '<p>'.__('You need to enter your Cookiebot ID.','cookiebot').'</p>';
207 echo '<p><a href="options-general.php?page=cookiebot">';
208 echo __('Update your Cookiebot ID','cookiebot');
209 echo '</a></p>';
210 }
211 else {
212 echo '<p>'._e('Your Cookiebot is working!','cookiebot').'</p>';
213 }
214 }
215
216 /**
217 * Cookiebot_WP Add option menu page for Cookiebot
218 *
219 * @version 2.2.0
220 * @since 1.0.0
221 */
222 function add_menu() {
223 //Cookiebot Icon SVG base64 encoded
224 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
225 add_menu_page( 'Cookiebot', __('Cookiebot','cookiebot'), 'manage_options', 'cookiebot', array($this,'settings_page'),$icon);
226
227 add_submenu_page('cookiebot',__('Cookiebot Settings','cookiebot'),__('Settings','cookiebot'), 'manage_options', 'cookiebot',array($this,'settings_page'));
228 add_submenu_page('cookiebot',__('Cookiebot Support','cookiebot'),__('Support','cookiebot'), 'manage_options', 'cookiebot_support',array($this,'support_page'));
229 add_submenu_page('cookiebot',__('IAB','cookiebot'),__('IAB','cookiebot'), 'manage_options', 'cookiebot_iab',array($this,'iab_page'));
230
231 if(defined('COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION')) {
232 //Load prior consent page anyway - but from Cookiebot WP Core plugin.
233 add_submenu_page( 'cookiebot', __( 'Prior Consent', 'cookiebot' ), __( 'Prior Consent', 'cookiebot' ), 'manage_options', 'cookiebot-addons', array($this,'setting_page_placeholder' ) );
234 }
235 }
236
237 /**
238 * Cookiebot_WP Add menu for network sites
239 *
240 * @version 2.2.0
241 * @since 2.2.0
242 */
243 function add_network_menu() {
244 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
245 add_menu_page( 'Cookiebot', __('Cookiebot','cookiebot'), 'manage_network_options', 'cookiebot_network', array($this,'network_settings_page'),$icon);
246
247 add_submenu_page('cookiebot_network',__('Cookiebot Settings','cookiebot'),__('Settings','cookiebot'), 'network_settings_page', 'cookiebot_network',array($this,'network_settings_page'));
248 add_submenu_page('cookiebot_network',__('Cookiebot Support','cookiebot'),__('Support','cookiebot'), 'network_settings_page', 'cookiebot_support',array($this,'support_page'));
249
250 }
251
252 /**
253 * Cookiebot_WP Cookiebot prior consent placeholder page
254 *
255 * @version 1.4.0
256 * @since 1.0.0
257 */
258 function setting_page_placeholder() {
259 include __DIR__ . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'view/admin/settings/setting-page.php';
260 }
261
262 /**
263 * Cookiebot_WP Register Cookiebot settings
264 *
265 * @version 2.1.5
266 * @since 1.0.0
267 */
268 function register_cookiebot_settings() {
269 register_setting('cookiebot', 'cookiebot-cbid');
270 register_setting('cookiebot', 'cookiebot-language');
271 register_setting('cookiebot', 'cookiebot-nooutput');
272 register_setting('cookiebot', 'cookiebot-nooutput-admin');
273 register_setting('cookiebot', 'cookiebot-autoupdate');
274 register_setting('cookiebot', 'cookiebot-script-tag-uc-attribute');
275 register_setting('cookiebot', 'cookiebot-script-tag-cd-attribute');
276 register_setting('cookiebot-iab', 'cookiebot-iab');
277 }
278
279 /**
280 * Cookiebot_WP Automatic update plugin if activated
281 *
282 * @version 2.2.0
283 * @since 1.5.0
284 */
285 function automatic_updates($update, $item) {
286 //Do not update from subsite on a multisite installation
287 if(is_multisite() && ! is_main_site()) {
288 return $update;
289 }
290
291 //Check if we have everything we need
292 $item = (array)$item;
293 if(!isset($item['new_version']) || !isset($item['slug'])) {
294 return $update;
295 }
296
297 //It is not Cookiebot
298 if($item['slug'] !== 'cookiebot') {
299 return $update;
300 }
301
302 // Check if cookiebot autoupdate is disabled
303 if(!get_option('cookiebot-autoupdate',false)) {
304 return $update;
305 }
306
307 // Check if multisite autoupdate is disabled
308 if(is_multisite() && !get_site_option('cookiebot-autoupdate',false)) {
309 return $update;
310 }
311
312 return true;
313 }
314
315
316 /**
317 * Cookiebot_WP Get list of supported languages
318 *
319 * @version 1.4.0
320 * @since 1.4.0
321 */
322 function get_supported_languages() {
323 $supportedLanguages = array();
324 $supportedLanguages['nb'] = __('Norwegian Bokmål','cookiebot');
325 $supportedLanguages['tr'] = __('Turkish','cookiebot');
326 $supportedLanguages['de'] = __('German','cookiebot');
327 $supportedLanguages['cs'] = __('Czech','cookiebot');
328 $supportedLanguages['da'] = __('Danish','cookiebot');
329 $supportedLanguages['sq'] = __('Albanian','cookiebot');
330 $supportedLanguages['he'] = __('Hebrew','cookiebot');
331 $supportedLanguages['ko'] = __('Korean','cookiebot');
332 $supportedLanguages['it'] = __('Italian','cookiebot');
333 $supportedLanguages['nl'] = __('Dutch','cookiebot');
334 $supportedLanguages['vi'] = __('Vietnamese','cookiebot');
335 $supportedLanguages['ta'] = __('Tamil','cookiebot');
336 $supportedLanguages['is'] = __('Icelandic','cookiebot');
337 $supportedLanguages['ro'] = __('Romanian','cookiebot');
338 $supportedLanguages['si'] = __('Sinhala','cookiebot');
339 $supportedLanguages['ca'] = __('Catalan','cookiebot');
340 $supportedLanguages['bg'] = __('Bulgarian','cookiebot');
341 $supportedLanguages['uk'] = __('Ukrainian','cookiebot');
342 $supportedLanguages['zh'] = __('Chinese','cookiebot');
343 $supportedLanguages['en'] = __('English','cookiebot');
344 $supportedLanguages['ar'] = __('Arabic','cookiebot');
345 $supportedLanguages['hr'] = __('Croatian','cookiebot');
346 $supportedLanguages['th'] = __('Thai','cookiebot');
347 $supportedLanguages['el'] = __('Greek','cookiebot');
348 $supportedLanguages['lt'] = __('Lithuanian','cookiebot');
349 $supportedLanguages['pl'] = __('Polish','cookiebot');
350 $supportedLanguages['lv'] = __('Latvian','cookiebot');
351 $supportedLanguages['fr'] = __('French','cookiebot');
352 $supportedLanguages['id'] = __('Indonesian','cookiebot');
353 $supportedLanguages['mk'] = __('Macedonian','cookiebot');
354 $supportedLanguages['et'] = __('Estonian','cookiebot');
355 $supportedLanguages['pt'] = __('Portuguese','cookiebot');
356 $supportedLanguages['ga'] = __('Irish','cookiebot');
357 $supportedLanguages['ms'] = __('Malay','cookiebot');
358 $supportedLanguages['sl'] = __('Slovenian','cookiebot');
359 $supportedLanguages['ru'] = __('Russian','cookiebot');
360 $supportedLanguages['ja'] = __('Japanese','cookiebot');
361 $supportedLanguages['hi'] = __('Hindi','cookiebot');
362 $supportedLanguages['sk'] = __('Slovak','cookiebot');
363 $supportedLanguages['es'] = __('Spanish','cookiebot');
364 $supportedLanguages['sv'] = __('Swedish','cookiebot');
365 $supportedLanguages['sr'] = __('Serbian','cookiebot');
366 $supportedLanguages['fi'] = __('Finnish','cookiebot');
367 $supportedLanguages['eu'] = __('Basque','cookiebot');
368 asort($supportedLanguages,SORT_LOCALE_STRING);
369 return $supportedLanguages;
370 }
371
372 /**
373 * Cookiebot_WP Output settings page
374 *
375 * @version 2.2.0
376 * @since 1.0.0
377 */
378 function settings_page() {
379 /* Check if multisite */
380 if($is_ms = is_multisite()) {
381 //Receive settings from multisite - this might change the way we render the form
382 $network_cbid = get_site_option('cookiebot-cbid','');
383 $network_scrip_tag_uc_attr = get_site_option('cookiebot-script-tag-uc-attribute','custom');
384 $network_scrip_tag_cd_attr = get_site_option('cookiebot-script-tag-cd-attribute','custom');
385 }
386 ?>
387 <div class="wrap">
388 <h1><?php _e('Cookiebot Settings','cookiebot'); ?></h1>
389 <a href="https://www.cookiebot.com">
390 <img src="<?php echo plugins_url( 'cookiebot-logo.png', __FILE__ ); ?>" style="float:right;margin-left:1em;">
391 </a>
392 <p>
393 <?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'); ?>
394 </p>
395 <form method="post" action="options.php">
396 <?php settings_fields( 'cookiebot' ); ?>
397 <?php do_settings_sections( 'cookiebot' ); ?>
398 <table class="form-table">
399 <tr valign="top">
400 <th scope="row"><?php _e('Cookiebot ID','cookiebot'); ?></th>
401 <td>
402 <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" />
403 <p class="description">
404 <?php _e('Need an ID?','cookiebot'); ?>
405 <a href="https://www.cookiebot.com/en/signup" target="_blank"><?php _e('Sign up for free on cookiebot.com','cookiebot'); ?></a>
406 </p>
407 </td>
408 </tr>
409 <tr valign="top">
410 <th scope="row"><?php _e('Cookiebot Language','cookiebot'); ?></th>
411 <td>
412 <div>
413 <select name="cookiebot-language" id="cookiebot-language">
414 <?php
415 $currentLang = $this->get_language(true);
416 ?>
417 <option value=""><?php _e('Default (Autodetect)','cookiebot'); ?></option>
418 <option value="_wp"<?php echo ($currentLang == '_wp') ? ' selected' : ''; ?>><?php _e('Use Wordpress Language','cookiebot'); ?></option>
419 <?php
420 $supportedLanguages = $this->get_supported_languages();
421 foreach($supportedLanguages as $langCode=>$langName) {
422 echo '<option value="'.$langCode.'"'.(($currentLang==$langCode) ? ' selected' : '').'>'.$langName.'</option>';
423 }
424 ?>
425 </select>
426 </div>
427 <div class="notice inline notice-warning notice-alt cookiebot-notice" style="padding:12px;font-size:13px;display:inline-block;">
428 <div style="<?php echo ($currentLang=='') ? 'display:none;' : '' ?>" id="info_lang_specified">
429 <?php _e('You need to add the language in the Cookiebot administration tool.'); ?>
430 </div>
431 <div style="<?php echo ($currentLang=='') ? '' : 'display:none;' ?>" id="info_lang_autodetect">
432 <?php _e('You need to add all languages that you want auto-detected in the Cookiebot administration tool.'); ?> <br/>
433 <?php _e('The auto-detect checkbox needs to be enabled in the Cookiebot administration tool.'); ?><br/>
434 <?php _e('If the auto-detected language is not supported, Cookiebot will use the default language.'); ?>
435 </div>
436 <br />
437
438 <a href="#" id="show_add_language_guide"><?php _e('Show guide to add languages'); ?></a>
439 &nbsp;
440 <a href="https://support.cookiebot.com/hc/en-us/articles/360003793394-How-do-I-set-the-language-of-the-consent-banner-dialog-" target="_blank">
441 <?php _e('Read more here'); ?>
442 </a>
443
444 <div id="add_language_guide" style="display:none;">
445 <img src="<?php echo plugin_dir_url( __FILE__ ); ?>/assets/guide_add_language.gif" alt="Add language in Cookiebot administration tool" />
446 <br />
447 <a href="#" id="hide_add_language_guide"><?php _e('Hide guide'); ?></a>
448 </div>
449 </div>
450 <script>
451 jQuery(document).ready(function($) {
452 $('#show_add_language_guide').on('click',function(e) {
453 e.preventDefault();
454 $('#add_language_guide').slideDown();
455 $(this).hide();
456 });
457 $('#hide_add_language_guide').on('click',function(e) {
458 e.preventDefault();
459 $('#add_language_guide').slideUp();
460 $('#show_add_language_guide').show();
461 });
462
463 $('#cookiebot-language').on('change', function() {
464 if(this.value == '') {
465 $('#info_lang_autodetect').show();
466 $('#info_lang_specified').hide();
467 }
468 else {
469 $('#info_lang_autodetect').hide();
470 $('#info_lang_specified').show();
471 }
472 });
473 });
474 </script>
475
476 </td>
477 </tr>
478 <tr valign="top">
479 <th scope="row">
480 <?php _e('Add async or defer attribute','cookiebot'); ?>
481 <br /><?php _e('Consent banner script tag'); ?>
482 </th>
483 <td>
484 <?php
485 $cv = get_option('cookiebot-script-tag-uc-attribute','async');
486 $disabled = false;
487 if($is_ms && $network_scrip_tag_uc_attr != 'custom') {
488 $disabled = true;
489 $cv = $network_scrip_tag_uc_attr;
490 }
491 ?>
492 <label>
493 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="" <?php checked('', $cv, true); ?> />
494 <i>None</i>
495 </label>
496 &nbsp; &nbsp;
497 <label>
498 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="async" <?php checked('async',$cv, true); ?> />
499 async
500 </label>
501 &nbsp; &nbsp;
502 <label>
503 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="defer" <?php checked('defer',$cv, true); ?> />
504 defer
505 </label>
506 <p class="description">
507 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
508 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: async','cookiebot') ?>
509 </p>
510 </td>
511 </tr>
512 <tr valign="top">
513 <th scope="row">
514 <?php _e('Add async or defer attribute','cookiebot'); ?>
515 <br /><?php _e('Cookie declaration script tag'); ?>
516 </th>
517 <td>
518 <?php
519 $cv = get_option('cookiebot-script-tag-cd-attribute','async');
520 $disabled = false;
521 if($is_ms && $network_scrip_tag_cd_attr != 'custom') {
522 $disabled = true;
523 $cv = $network_scrip_tag_cd_attr;
524 }
525 ?>
526 <label>
527 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="" <?php checked('', $cv, true); ?> />
528 <i>None</i>
529 </label>
530 &nbsp; &nbsp;
531 <label>
532 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="async" <?php checked('async',$cv, true); ?> />
533 async
534 </label>
535 &nbsp; &nbsp;
536 <label>
537 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ($disabled) ? ' disabled' : ''; ?> value="defer" <?php checked('defer',$cv, true); ?> />
538 defer
539 </label>
540 <p class="description">
541 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
542 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: async','cookiebot') ?>
543 </p>
544 </td>
545 </tr>
546 <?php
547 if(!is_multisite()) {
548 ?>
549 <tr valign="top">
550 <th scope="row"><?php _e('Auto-update Cookiebot','cookiebot'); ?></th>
551 <td>
552 <input type="checkbox" name="cookiebot-autoupdate" value="1" <?php checked(1,get_option('cookiebot-autoupdate',false), true); ?> />
553 <p class="description">
554 <?php _e('Automatic update your Cookiebot plugin when new releases becomes available.','cookiebot') ?>
555 </p>
556 </td>
557 </tr>
558 <?php
559 }
560 ?>
561 <tr valign="top">
562 <th scope="row"><?php _e('Hide Cookie Popup','cookiebot'); ?></th>
563 <td>
564 <?php
565 $disabled = false;
566 if($is_ms && get_site_option('cookiebot-nooutput',false)) {
567 $disabled = true;
568 echo '<input type="checkbox" checked disabled />';
569 }
570 else {
571 ?>
572 <input type="checkbox" name="cookiebot-nooutput" value="1" <?php checked(1,get_option('cookiebot-nooutput',false), true); ?> />
573 <?php
574 }
575 ?>
576 <p class="description">
577 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
578 <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 />
579 <?php _e('If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.','cookiebot') ?><br />
580 <?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') ?>
581 </p>
582 </td>
583 </tr>
584 <tr valign="top">
585 <th scope="row"><?php _e('Hide Cookie Popup in WP Admin','cookiebot'); ?></th>
586 <td>
587 <?php
588 $disabled = false;
589 if($is_ms && get_site_option('cookiebot-nooutput-admin',false)) {
590 echo '<input type="checkbox" checked disabled />';
591 $disabled = true;
592 }
593 else {
594 ?>
595 <input type="checkbox" name="cookiebot-nooutput-admin" value="1" <?php checked(1,get_option('cookiebot-nooutput-admin',false), true); ?> />
596 <?php
597 }
598 ?>
599 <p class="description">
600 <?php if($disabled) { echo '<b>'._('Network setting applied. Please contact website administrator to change this setting.').'</b><br />'; } ?>
601 <b><?php _e('This checkbox will remove the cookie consent banner the Wordpress Admin area.','cookiebot') ?></b>
602 </p>
603 </td>
604 </tr>
605 </table>
606 <?php submit_button(); ?>
607 </form>
608 </div>
609 <?php
610 }
611
612 /**
613 * Cookiebot_WP Cookiebot network setting page
614 *
615 * @version 2.2.0
616 * @since 2.2.0
617 */
618 function network_settings_page() {
619 ?>
620 <div class="wrap">
621 <h1><?php _e('Cookiebot Network Settings','cookiebot'); ?></h1>
622 <a href="https://www.cookiebot.com">
623 <img src="<?php echo plugins_url( 'cookiebot-logo.png', __FILE__ ); ?>" style="float:right;margin-left:1em;">
624 </a>
625 <p>
626 <?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'); ?>
627 </p>
628 <p>
629 <b><big style="color:red;"><?php _e('The settings below is network wide settings. See notes below each field.'); ?></big></b>
630 </p>
631 <form method="post" action="edit.php?action=cookiebot_network_settings">
632 <?php wp_nonce_field( 'cookiebot-network-settings' ); ?>
633 <table class="form-table">
634 <tr valign="top">
635 <th scope="row"><?php _e('Network Cookiebot ID','cookiebot'); ?></th>
636 <td>
637 <input type="text" name="cookiebot-cbid" value="<?php echo esc_attr( get_site_option('cookiebot-cbid','') ); ?>" style="width:300px" />
638 <p class="description">
639 <b><?php _e('If added this will be the default Cookiebot ID for all subsites. Subsites are able to override the Cookiebot ID.'); ?></b>
640 <br />
641 <?php _e('Need an ID?','cookiebot'); ?>
642 <a href="https://www.cookiebot.com/en/signup" target="_blank"><?php _e('Sign up for free on cookiebot.com','cookiebot'); ?></a>
643 </p>
644 </td>
645 </tr>
646 <tr valign="top">
647 <th scope="row">
648 <?php _e('Add async or defer attribute','cookiebot'); ?>
649 <br /><?php _e('Consent banner script tag'); ?>
650 </th>
651 <td>
652 <?php
653 $cv = get_site_option('cookiebot-script-tag-uc-attribute','custom');
654 ?>
655 <label>
656 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="" <?php checked('', $cv, true); ?> />
657 <i>None</i>
658 </label>
659 &nbsp; &nbsp;
660 <label>
661 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="async" <?php checked('async',$cv, true); ?> />
662 async
663 </label>
664 &nbsp; &nbsp;
665 <label>
666 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="defer" <?php checked('defer',$cv, true); ?> />
667 defer
668 </label>
669 &nbsp; &nbsp;
670 <label>
671 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="custom" <?php checked('custom',$cv, true); ?> />
672 <i>Choose per subsite</i>
673 </label>
674 <p class="description">
675 <b><?php _e('Setting will apply for all subsites. Subsites will not be able to override.'); ?></b><br />
676 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite','cookiebot') ?>
677 </p>
678 </td>
679 </tr>
680 <tr valign="top">
681 <th scope="row">
682 <?php _e('Add async or defer attribute','cookiebot'); ?>
683 <br /><?php _e('Cookie declaration script tag'); ?>
684 </th>
685 <td>
686 <?php
687 $cv = get_site_option('cookiebot-script-tag-cd-attribute','custom');
688 ?>
689 <label>
690 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="" <?php checked('', $cv, true); ?> />
691 <i>None</i>
692 </label>
693 &nbsp; &nbsp;
694 <label>
695 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="async" <?php checked('async',$cv, true); ?> />
696 async
697 </label>
698 &nbsp; &nbsp;
699 <label>
700 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="defer" <?php checked('defer',$cv, true); ?> />
701 defer
702 </label>
703 &nbsp; &nbsp;
704 <label>
705 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="custom" <?php checked('custom',$cv, true); ?> />
706 <i>Choose per subsite</i>
707 </label>
708 <p class="description">
709 <b><?php _e('Setting will apply for all subsites. Subsites will not be able to override.'); ?></b><br />
710 <?php _e('Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite','cookiebot') ?>
711 </p>
712 </td>
713 </tr>
714 <tr valign="top">
715 <th scope="row"><?php _e('Auto-update Cookiebot','cookiebot'); ?></th>
716 <td>
717 <input type="checkbox" name="cookiebot-autoupdate" value="1" <?php checked(1,get_site_option('cookiebot-autoupdate',false), true); ?> />
718 <p class="description">
719 <?php _e('Automatic update your Cookiebot plugin when new releases becomes available.','cookiebot') ?>
720 </p>
721 </td>
722 </tr>
723 <tr valign="top">
724 <th scope="row"><?php _e('Hide Cookie Popup','cookiebot'); ?></th>
725 <td>
726 <input type="checkbox" name="cookiebot-nooutput" value="1" <?php checked(1,get_site_option('cookiebot-nooutput',false), true); ?> />
727 <p class="description">
728 <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 />
729 <?php _e('If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.','cookiebot') ?><br />
730 <?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') ?>
731 </p>
732 </td>
733 </tr>
734 <tr valign="top">
735 <th scope="row"><?php _e('Hide Cookie Popup in WP Admin','cookiebot'); ?></th>
736 <td>
737 <input type="checkbox" name="cookiebot-nooutput-admin" value="1" <?php checked(1,get_site_option('cookiebot-nooutput-admin',false), true); ?> />
738 <p class="description">
739 <b><?php _e('Remove the cookie consent banner the Wordpress Admin area for all subsites. This cannot be changed by subsites.','cookiebot') ?></b>
740 </p>
741 </td>
742 </tr>
743 </table>
744 <?php submit_button(); ?>
745 </form>
746 </div>
747 <?php
748 }
749
750
751 /**
752 * Cookiebot_WP Cookiebot save network settings
753 *
754 * @version 2.2.0
755 * @since 2.2.0
756 */
757 function network_settings_save() {
758 check_admin_referer( 'cookiebot-network-settings' );
759
760 update_site_option('cookiebot-cbid', $_POST['cookiebot-cbid'] );
761 update_site_option('cookiebot-script-tag-uc-attribute', $_POST['cookiebot-script-tag-uc-attribute'] );
762 update_site_option('cookiebot-script-tag-cd-attribute', $_POST['cookiebot-script-tag-cd-attribute'] );
763 update_site_option('cookiebot-autoupdate', $_POST['cookiebot-autoupdate'] );
764 update_site_option('cookiebot-nooutput', $_POST['cookiebot-nooutput'] );
765 update_site_option('cookiebot-nooutput-admin', $_POST['cookiebot-nooutput-admin'] );
766
767 wp_redirect( add_query_arg( array(
768 'page' => 'cookiebot_network',
769 'updated' => true ), network_admin_url('admin.php')
770 ));
771 exit;
772 }
773
774 /**
775 * Cookiebot_WP Cookiebot support page
776 *
777 * @version 2.2.0
778 * @since 2.0.0
779 */
780 function support_page() {
781 ?>
782 <div class="wrap">
783 <h1><?php _e('Support','cookiebot'); ?></h1>
784 <h2><?php _e('How to find my Cookiebot ID','cookiebot'); ?></h2>
785 <p>
786 <ol>
787 <li><?php _e('Log in to your <a href="https://www.cookiebot.com/en/account" target="_blank">Cookiebot account</a>.','cookiebot'); ?></li>
788 <li><?php _e('Go to <b>Manage</b> > <b>Settings</b> and add setup your Cookiebot','cookiebot'); ?></li>
789 <li><?php _e('Go to the <b>"Your scripts"</b> tab','cookiebot'); ?></li>
790 <li><?php _e('Copy the value inside the data-cid parameter - eg.: abcdef12-3456-7890-abcd-ef1234567890','cookiebot'); ?></li>
791 <li><?php _e('Add <b>[cookie_declaration]</b> shortcode to a page to show the declation','cookiebot'); ?></li>
792 <li><?php _e('Remember to change your scripts as descripted below','cookiebot'); ?></li>
793 </ol>
794 </p>
795 <h2><?php _e('Add the Cookie Declaration to your website'); ?></h2>
796 <p>
797 <?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'); ?>
798 <br />
799 <?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'); ?>
800 </p>
801 <p>
802 <a href="https://www.youtube.com/watch?v=OCXz2bt4H_w" target="_blank" class="button"><?php _e('Watch video demonstration','cookiebot'); ?></a>
803 </p>
804 <h2><?php _e('Update your script tags','cookiebot'); ?></h2>
805 <p>
806 <?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'); ?>
807 </p>
808 <code>
809 <?php
810 echo htmlentities("<script type=\"text/plain\" data-cookieconsent=\"statistics\">").'<br />';
811 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 />';
812 echo htmlentities("ga('create', 'UA-00000000-0', 'auto');").'<br />';
813 echo htmlentities("ga('send', 'pageview');").'<br />';
814 echo htmlentities("</script>").'<br />';
815 ?>
816 </code>
817 <p>
818 <a href="https://www.youtube.com/watch?v=MeHycvV2QCQ" target="_blank" class="button"><?php _e('Watch video demonstration','cookiebot'); ?></a>
819 </p>
820
821 <h2><?php _e('Helper function to update your scripts','cookiebot'); ?></h2>
822 <p>
823 <?php _e('You are able to update your scripts yourself. However, Cookiebot also offers a small helper function that makes the work easier.','cookiebot'); ?>
824 <br />
825 <?php _e('Update your script tags this way:','cookiebot'); ?>
826 </p>
827 <?php
828 printf(
829 __('%s to %s'),
830 '<code>'.htmlentities('<script type="text/javascript">').'</code>',
831 '<code>'.htmlentities('<script<?php echo cookiebot_assist(\'marketing\') ?>>').'</code>'
832 );
833 ?>
834 </div>
835 <?php
836 }
837
838 /**
839 * Cookiebot_WP Cookiebot IAB page
840 *
841 * @version 2.0.0
842 * @since 2.0.0
843 */
844 function iab_page() {
845 ?>
846 <div class="wrap">
847 <h1><?php _e('IAB','cookiebot'); ?></h1>
848
849 <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>
850
851 <form method="post" action="options.php">
852 <?php settings_fields( 'cookiebot-iab' ); ?>
853 <?php do_settings_sections( 'cookiebot-iab' ); ?>
854
855 <label>Enable IAB integration</label>
856 <input type="checkbox" name="cookiebot-iab" value="1" <?php checked(1,get_option('cookiebot-iab'), true); ?>>
857
858 <?php submit_button(); ?>
859 </form>
860 </div>
861 <?php
862 }
863
864 /**
865 * Cookiebot_WP Add Cookiebot JS to <head>
866 *
867 * @version 2.2.0
868 * @since 1.0.0
869 */
870 function add_js() {
871 $cbid = $this->get_cbid();
872 if(!empty($cbid)) {
873 if(is_multisite() && get_site_option('cookiebot-nooutput',false)) {
874 return; //Is multisite - and disabled output is checked as network setting
875 }
876 if(get_option('cookiebot-nooutput',false)) {
877 return; //Do not show JS - output disabled
878 }
879
880
881 $lang = $this->get_language();
882 if(!empty($lang)) {
883 $lang = ' data-culture="'.strtoupper($lang).'"'; //Use data-culture to define language
884 }
885
886 if(!is_multisite() || get_site_option('cookiebot-script-tag-uc-attribute','custom') == 'custom') {
887 $tagAttr = get_option('cookiebot-script-tag-uc-attribute','async');
888 }
889 else {
890 $tagAttr = get_site_option('cookiebot-script-tag-uc-attribute');
891 }
892
893 $iab = ( get_option('cookiebot-iab') != false ) ? 'data-framework="IAB"' : '';
894 ?>
895 <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>
896 <?php
897 }
898 }
899
900 /**
901 * Cookiebot_WP Output declation shortcode [cookie_declaration]
902 * Support attribute lang="LANGUAGE_CODE". Eg. lang="en".
903 *
904 * @version 2.2.0
905 * @since 1.0.0
906 */
907 function show_declaration($atts) {
908 $cbid = $this->get_cbid();
909 $lang = '';
910 if(!empty($cbid)) {
911
912 $atts = shortcode_atts(array(
913 'lang' => $this->get_language(),
914 ), $atts, 'cookie_declaration'
915 );
916
917 if(!empty($atts['lang'])) {
918 $lang = ' data-culture="'.strtoupper($atts['lang']).'"'; //Use data-culture to define language
919 }
920
921 if(!is_multisite() || get_site_option('cookiebot-script-tag-cd-attribute','custom') == 'custom') {
922 $tagAttr = get_option('cookiebot-script-tag-cd-attribute','async');
923 }
924 else {
925 $tagAttr = get_site_option('cookiebot-script-tag-cd-attribute');
926 }
927
928 return '<script id="CookieDeclaration" src="https://consent.cookiebot.com/'.$cbid.'/cd.js"'.$lang.' type="text/javascript" '.$tagAttr.'></script>';
929 }
930 else {
931 return __('Please add your Cookiebot ID to show Cookie Declarations','cookiebot');
932 }
933 }
934
935 /**
936 * Cookiebot_WP Get cookiebot cbid
937 *
938 * @version 2.2.0
939 * @since 1.0.0
940 */
941 public static function get_cbid() {
942 $cbid = get_option('cookiebot-cbid');
943 if(is_multisite() && ($network_cbid = get_site_option('cookiebot-cbid'))) {
944 if(empty($cbid)) {
945 return $network_cbid;
946 }
947 }
948 return $cbid;
949 }
950
951 /**
952 * Cookiebot_WP Get the language code for Cookiebot
953 *
954 * @version 1.4.0
955 * @since 1.4.0
956 */
957 function get_language($onlyFromSetting=false) {
958 // Get language set in setting page - if empty use WP language info
959 $lang = get_option('cookiebot-language');
960 if(!empty($lang)) {
961 if($lang != '_wp') {
962 return $lang;
963 }
964 }
965
966 if($onlyFromSetting) {
967 return $lang; //We want only to get if already set
968 }
969
970 //Language not set - use WP language
971 if($lang == '_wp') {
972 $lang = get_bloginfo('language'); //Gets language in en-US format
973 if(!empty($lang)) {
974 list($lang) = explode('-',$lang); //Changes format from eg. en-US to en.
975 }
976 }
977 return $lang;
978 }
979
980 /**
981 * Cookiebot_WP Adding Cookiebot domain(s) to exclude list for WP Rocket minification.
982 *
983 * @version 1.6.1
984 * @since 1.6.1
985 */
986 function wp_rocket_exclude_external_js($external_js_hosts) {
987 $external_js_hosts[] = 'consent.cookiebot.com'; // Add cookiebot domains
988 $external_js_hosts[] = 'consentcdn.cookiebot.com';
989 return $external_js_hosts;
990 }
991
992 /**
993 * Display admin notice for recommending cookiebot
994 *
995 * @version 2.0.5
996 * @since 2.0.5
997 */
998 function cookiebot_admin_notices() {
999 if( ! $this->cookiebot_valid_admin_recommendation() ) {
1000 return false;
1001 }
1002 $two_week_review_ignore = add_query_arg( array( 'cookiebot_admin_notice' => 'hide' ) );
1003 $two_week_review_temp = add_query_arg( array( 'cookiebot_admin_notice' => 'two_week' ) );
1004
1005 $notices = array(
1006 'title' => __('Leave A Review?', 'cookiebot'),
1007 'msg' => __('We hope you enjoy using WordPress Cookiebot! Would you consider leaving us a review on WordPress.org?', 'cookiebot'),
1008 '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>
1009 <li><span class="dashicons dashicons-smiley"></span><a href="' . $two_week_review_ignore . '"> ' . __('I\'ve already left a review', 'cookiebot') . '</a></li>
1010 <li><span class="dashicons dashicons-calendar-alt"></span><a href="' . $two_week_review_temp . '">' . __('Maybe Later', 'cookiebot') . '</a></li>
1011 <li><span class="dashicons dashicons-dismiss"></span><a href="' . $two_week_review_ignore . '">' . __('Never show again', 'cookiebot') . '</a></li>',
1012 'later_link' => $two_week_review_temp,
1013 'int' => 14
1014 );
1015
1016 echo '<div class="update-nag cookiebot-admin-notice">
1017 <div class="cookiebot-notice-logo"></div>
1018 <p class="cookiebot-notice-title">' . $notices['title'] . '</p>
1019 <p class="cookiebot-notice-body">' . $notices['msg'] . '</p>
1020 <ul class="cookiebot-notice-body wd-blue">' . $notices['link'] . '</ul>
1021 <a href="' . $notices['later_link'] . '" class="dashicons dashicons-dismiss"></a>
1022 </div>';
1023
1024 wp_enqueue_style( 'cookiebot-admin-notices', plugins_url( 'css/notice.css', __FILE__ ), array(), '2.0.4' );
1025 }
1026
1027
1028 /**
1029 * Validate if the last user action is valid for plugin recommendation
1030 *
1031 * @return bool
1032 *
1033 * @version 2.0.5
1034 * @since 2.0.5
1035 */
1036 function cookiebot_valid_admin_recommendation() {
1037 //Default - the recommendation is allowed to be visible
1038 $return = true;
1039
1040 $option = get_option('cookiebot_notice_recommend');
1041
1042 if( $option != false ) {
1043 //Never show again is clicked
1044 if( $option == 'hide' ) {
1045 $return = false;
1046 }
1047 elseif( is_numeric($option) && strtotime('now') < $option ) {
1048 //Show me after 2 weeks is clicked and the time is not valid yet
1049 $return = false;
1050 }
1051 }
1052 return $return;
1053 }
1054
1055 /**
1056 * Save the user action on cookiebot recommendation link
1057 *
1058 * @version 2.0.5
1059 * @since 2.0.5
1060 */
1061 function save_notice_link() {
1062 if( isset( $_GET['cookiebot_admin_notice'] ) ) {
1063 if( $_GET['cookiebot_admin_notice'] == 'hide' ) {
1064 update_option('cookiebot_notice_recommend', 'hide' );
1065 }
1066 else {
1067 update_option('cookiebot_notice_recommend', strtotime('+2 weeks') );
1068 }
1069 }
1070 }
1071
1072 }
1073 endif;
1074
1075
1076 /**
1077 * Helper function to manipulate script tags
1078 *
1079 * @version 1.6
1080 * @since 1.0
1081 * @return string
1082 */
1083 function cookiebot_assist($type='statistics') {
1084 //change to array
1085 if(!is_array($type)) { $type = array($type); }
1086
1087 foreach($type as $tk=>$tv) {
1088 if(!in_array($tv,array('marketing','statistics','preferences'))) {
1089 unset($type[$tk]);
1090 }
1091 }
1092 if(sizeof($type) > 0) {
1093 return ' type="text/plain" data-cookieconsent="'.implode(',',$type).'"';
1094 }
1095 return '';
1096 }
1097
1098
1099 /**
1100 * Helper function to check if cookiebot is active.
1101 * Useful for other plugins adding support for Cookiebot.
1102 *
1103 * @version 2.2.2
1104 * @since 1.2
1105 * @return string
1106 */
1107 function cookiebot_active() {
1108 $cbid = Cookiebot_WP::get_cbid();
1109 if(!empty($cbid)) {
1110 return true;
1111 }
1112 return false;
1113 }
1114
1115
1116 if(!function_exists('cookiebot')) {
1117 /**
1118 * Returns the main instance of Cookiebot_WO to prevent the need to use globals.
1119 *
1120 * @version 1.0.0
1121 * @since 1.0.0
1122 * @return Cookiebot_WP
1123 */
1124 function cookiebot() {
1125 return Cookiebot_WP::instance();
1126 }
1127 }
1128
1129 cookiebot();
1130