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