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