PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 3.11.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v3.11.2
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / cookiebot.php
cookiebot Last commit date
addons 4 years ago assets 7 years ago bin 5 years ago css 6 years ago documentation 7 years ago js 5 years ago langs 4 years ago tests 4 years ago widgets 4 years ago CookiebotAPI.md 7 years ago LICENSE.txt 8 years ago README.md 5 years ago cookiebot-logo.png 4 years ago cookiebot.php 4 years ago phpunit.xml 5 years ago readme.txt 4 years ago
cookiebot.php
2647 lines
1 <?php
2 /*
3 Plugin Name: Cookiebot | GDPR/CCPA Compliant Cookie Consent and Control
4 Plugin URI: https://cookiebot.com/
5 Description: Cookiebot is a cloud-driven solution that automatically controls cookies and trackers, enabling full GDPR/ePrivacy and CCPA compliance for websites.
6 Author: Cybot A/S
7 Version: 3.11.2
8 Author URI: http://cookiebot.com
9 Text Domain: cookiebot
10 Domain Path: /langs
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly
15 }
16
17 if ( ! class_exists( 'Cookiebot_WP' ) ) :
18
19 final class Cookiebot_WP {
20 /**
21 * Plugin version.
22 *
23 * @var string
24 * @since 1.0.0
25 */
26 public $version = '3.11.2';
27
28 /**
29 * @var Cookiebot_WP The single instance of the class
30 * @since 1.0.0
31 */
32 protected static $instance = null;
33
34 /**
35 * Main Cookiebot_WP Instance
36 *
37 * Ensures only one instance of Cookiebot_WP is loaded or can be loaded.
38 *
39 * @return Cookiebot_WP - Main instance
40 * @since 1.0.0
41 * @static
42 * @version 1.0.0
43 */
44 public static function instance() {
45 if ( is_null( self::$instance ) ) {
46 self::$instance = new self();
47 }
48
49 return self::$instance;
50 }
51
52 /**
53 * Cookiebot_WP Constructor.
54 *
55 * @version 2.1.4
56 * @since 1.0.0
57 * @access public
58 */
59 public function __construct() {
60 add_action( 'after_setup_theme', array( $this, 'cookiebot_init' ), 5 );
61 register_activation_hook( __FILE__, array( $this, 'activation' ) );
62 register_deactivation_hook( __FILE__, 'cookiebot_addons_plugin_deactivated' );
63
64 $this->cookiebot_fix_plugin_conflicts();
65 }
66
67 /**
68 * Cookiebot_WP Installation actions
69 *
70 * @version 2.1.4
71 * @since 2.1.4
72 * @accces public
73 */
74 public function activation() {
75 //Delay display of recommendation notice in 3 days if not activated ealier
76 if ( get_option( 'cookiebot_notice_recommend', false ) === false ) {
77 //Not set yet - this must be first activation - delay in 3 days
78 update_option( 'cookiebot_notice_recommend', strtotime( '+3 days' ) );
79 }
80 if ( $this->get_cbid() === '' ) {
81 if ( is_multisite() ) {
82 update_site_option( 'cookiebot-cookie-blocking-mode', 'auto' );
83 update_site_option( 'cookiebot-nooutput-admin', true );
84 } else {
85 update_option( 'cookiebot-cookie-blocking-mode', 'auto' );
86 update_option( 'cookiebot-nooutput-admin', true );
87 }
88 }
89
90 /**
91 * Run through the addons and enable the default ones
92 */
93 if ( ( ! defined( 'COOKIEBOT_ADDONS_STANDALONE' ) || COOKIEBOT_ADDONS_STANDALONE !== true || ! defined( 'COOKIE_ADDONS_LOADED' ) ) ) {
94 //Make sure we got a PHP version that works
95 if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) {
96 define( 'COOKIEBOT_URL', plugin_dir_url( __FILE__ ) );
97 // activation hook doesn't have the addons loaded - so load it extra when the plugin is activated
98 include_once dirname( __FILE__ ) . '/addons/cookiebot-addons-init.php';
99 // run activated hook on the addons
100 cookiebot_addons_plugin_activated();
101 }
102 }
103 }
104
105 /**
106 * Cookiebot_WP Init Cookiebot.
107 *
108 * @version 3.8.1
109 * @since 1.6.2
110 * @access public
111 */
112 public function cookiebot_init() {
113 /* Load Cookiebot Addons Framework */
114 $dismiss_addons = false;
115 if ( defined( 'CAF_DIR' ) ) {
116 $dismiss_addons = true;
117 /*add_action('admin_notices', function() {
118 ?>
119 <div class="notice notice-warning">
120 <p>
121 <?php esc_html_e( 'You have Cookiebot Addons installed.', 'cookiebot' ); ?><br />
122 <?php esc_html_e( 'In this and future releases of Cookiebot all available Addons are bundled directly with the Cookiebot plugin.', 'cookiebot' ); ?><br />
123 <?php esc_html_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' ); ?>
124 </p>
125 </div>
126 <?php
127 });*/
128 } //elseif( $this->get_cookie_blocking_mode() !== 'auto' ) {
129 else {
130 if ( ( ! defined( 'COOKIEBOT_ADDONS_STANDALONE' ) || COOKIEBOT_ADDONS_STANDALONE !== true || ! defined( 'COOKIE_ADDONS_LOADED' ) ) && $dismiss_addons !== true ) {
131 //Make sure we got a PHP version that works
132 if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) {
133 define( 'COOKIEBOT_URL', plugin_dir_url( __FILE__ ) );
134 include_once dirname( __FILE__ ) . '/addons/cookiebot-addons-init.php';
135 } else {
136 define( 'COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION', true );
137 }
138 } else {
139 add_action(
140 'admin_notices',
141 function () {
142 ?>
143 <div class="notice notice-warning">
144 <p>
145 <?php esc_html_e( 'You are using Cookiebot Addons Standalone.', 'cookiebot' ); ?>
146 </p>
147 </div>
148 <?php
149 }
150 );
151 }
152 }
153 if ( is_admin() ) {
154
155 //Adding menu to WP admin
156 add_action( 'admin_menu', array( $this, 'add_menu' ), 1 );
157 add_action( 'admin_menu', array( $this, 'add_menu_legislations' ), 40 );
158 add_action( 'admin_menu', array( $this, 'add_menu_debug' ), 50 );
159
160 if ( is_multisite() ) {
161 add_action( 'network_admin_menu', array( $this, 'add_network_menu' ), 1 );
162 add_action( 'network_admin_edit_cookiebot_network_settings', array( $this, 'network_settings_save' ) );
163 }
164
165 //Register settings
166 add_action( 'admin_init', array( $this, 'register_cookiebot_settings' ) );
167
168 //Adding dashboard widgets
169 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) );
170
171 add_action( 'admin_notices', array( $this, 'cookiebot_admin_notices' ) );
172 add_action( 'admin_init', array( $this, 'save_notice_link' ) );
173
174 //Check if we should show cookie consent banner on admin pages
175 if ( ! $this->cookiebot_disabled_in_admin() ) {
176 //adding cookie banner in admin area too
177 add_action( 'admin_head', array( $this, 'add_js' ), - 9999 );
178 }
179 }
180
181 //Include integration to WP Consent Level API if available
182 if ( $this->is_wp_consent_api_active() ) {
183 add_action( 'wp_enqueue_scripts', array( $this, 'cookiebot_enqueue_consent_api_scripts' ) );
184 }
185
186 // Set up localisation
187 load_plugin_textdomain( 'cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
188
189 //add JS
190 add_action( 'wp_head', array( $this, 'add_js' ), - 9997 );
191 add_action( 'wp_head', array( $this, 'add_GTM' ), - 9998 );
192 add_action( 'wp_head', array( $this, 'add_GCM' ), - 9999 );
193 add_shortcode( 'cookie_declaration', array( $this, 'show_declaration' ) );
194
195 //Add filter if WP rocket is enabled
196 if ( defined( 'WP_ROCKET_VERSION' ) ) {
197 add_filter( 'rocket_minify_excluded_external_js', array( $this, 'wp_rocket_exclude_external_js' ) );
198 }
199
200 //Add filter
201 add_filter( 'sgo_javascript_combine_excluded_external_paths', array( $this, 'sgo_exclude_external_js' ) );
202
203 //Automatic update plugin
204 if ( is_admin() || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
205 add_filter( 'auto_update_plugin', array( $this, 'automatic_updates' ), 10, 2 );
206 }
207
208 //Loading widgets
209 include_once dirname( __FILE__ ) . '/widgets/cookiebot-declaration-widget.php';
210 add_action( 'widgets_init', array( $this, 'register_widgets' ) );
211
212 //Add Gutenberg block
213 add_action( 'init', array( $this, 'gutenberg_block_setup' ) );
214 add_action( 'enqueue_block_editor_assets', array( $this, 'gutenberg_block_admin_assets' ) );
215 }
216
217
218 /**
219 * Cookiebot_WP Setup Gutenberg block
220 *
221 * @version 3.7.0
222 * @since 3.7.0
223 */
224 public function gutenberg_block_setup() {
225 if ( ! function_exists( 'register_block_type' ) ) {
226 return; //gutenberg not active
227 }
228
229 register_block_type(
230 'cookiebot/cookie-declaration',
231 array(
232 'render_callback' => array( $this, 'block_cookie_declaration' ),
233 )
234 );
235 }
236
237 /**
238 * Cookiebot_WP Add block JS
239 *
240 * @version 3.7.1
241 * @since 3.7.1
242 */
243 public function gutenberg_block_admin_assets() {
244 //Add Gutenberg Widget
245 wp_enqueue_script(
246 'cookiebot-declaration',
247 plugin_dir_url( __FILE__ ) . 'js/block.js',
248 array( 'wp-blocks', 'wp-i18n', 'wp-element' ), // Required scripts for the block
249 $this->version
250 );
251 }
252
253 /**
254 * Cookiebot_WP Render Cookiebot Declaration as Gutenberg block
255 *
256 * @version 3.7.0
257 * @since 3.7.0
258 */
259 public function block_cookie_declaration() {
260 return $this->show_declaration();
261 }
262
263 /**
264 * Cookiebot_WP Load text domain
265 *
266 * @version 2.0.0
267 * @since 2.0.0
268 */
269 public function load_textdomain() {
270 load_plugin_textdomain( 'cookiebot', false, basename( dirname( __FILE__ ) ) . '/langs' );
271 }
272
273 /**
274 * Cookiebot_WP Register widgets
275 *
276 * @version 2.5.0
277 * @since 2.5.0
278 */
279 public function register_widgets() {
280 register_widget( 'Cookiebot_Declaration_Widget' );
281 }
282
283 /**
284 * Cookiebot_WP Add dashboard widgets to admin
285 *
286 * @version 1.0.0
287 * @since 1.0.0
288 */
289
290 public function add_dashboard_widgets() {
291 wp_add_dashboard_widget( 'cookiebot_status', esc_html__( 'Cookiebot Status', 'cookiebot' ), array( $this, 'dashboard_widget_status' ) );
292 }
293
294 /**
295 * Cookiebot_WP Output Dashboard Status Widget
296 *
297 * @version 1.0.0
298 * @since 1.0.0
299 */
300 public function dashboard_widget_status() {
301 $cbid = $this->get_cbid();
302 if ( empty( $cbid ) ) {
303 echo '<p>' . esc_html__( 'You need to enter your Cookiebot ID.', 'cookiebot' ) . '</p>';
304 echo '<p><a href="options-general.php?page=cookiebot">';
305 echo esc_html__( 'Update your Cookiebot ID', 'cookiebot' );
306 echo '</a></p>';
307 } else {
308 echo '<p>' . esc_html_e( 'Your Cookiebot is working!', 'cookiebot' ) . '</p>';
309 }
310 }
311
312 /**
313 * Cookiebot_WP Add option menu page for Cookiebot
314 *
315 * @version 2.2.0
316 * @since 1.0.0
317 */
318 public function add_menu() {
319 //Cookiebot Icon SVG base64 encoded
320 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
321 add_menu_page( 'Cookiebot', __( 'Cookiebot', 'cookiebot' ), 'manage_options', 'cookiebot', array( $this, 'settings_page' ), $icon );
322
323 add_submenu_page(
324 'cookiebot',
325 __( 'Cookiebot Settings', 'cookiebot' ),
326 __( 'Settings', 'cookiebot' ),
327 'manage_options',
328 'cookiebot',
329 array( $this, 'settings_page' ),
330 10
331 );
332 add_submenu_page(
333 'cookiebot',
334 __( 'Cookiebot Support', 'cookiebot' ),
335 __( 'Support', 'cookiebot' ),
336 'manage_options',
337 'cookiebot_support',
338 array( $this, 'support_page' ),
339 20
340 );
341 add_submenu_page(
342 'cookiebot',
343 __( 'Google Tag Manager', 'cookiebot' ),
344 __( 'Google Tag Manager', 'cookiebot' ),
345 'manage_options',
346 'cookiebot_GTM',
347 array( $this, 'GTM_page' )
348 );
349 add_submenu_page(
350 'cookiebot',
351 __( 'IAB', 'cookiebot' ),
352 __( 'IAB', 'cookiebot' ),
353 'manage_options',
354 'cookiebot_iab',
355 array( $this, 'iab_page' ),
356 30
357 );
358
359 if ( defined( 'COOKIEBOT_ADDONS_UNSUPPORTED_PHPVERSION' ) ) {
360 //Load prior consent page anyway - but from Cookiebot WP Core plugin.
361 add_submenu_page(
362 'cookiebot',
363 __( 'Prior Consent', 'cookiebot' ),
364 __( 'Prior Consent', 'cookiebot' ),
365 'manage_options',
366 'cookiebot-addons',
367 array( $this, 'setting_page_placeholder' ),
368 40
369 );
370 }
371 }
372
373 public function add_menu_legislations() {
374 add_submenu_page(
375 'cookiebot',
376 __( 'Legislations', 'cookiebot' ),
377 __( 'Legislations', 'cookiebot' ),
378 'manage_options',
379 'cookiebot-legislations',
380 array( $this, 'legislations_page' ),
381 50
382 );
383 }
384
385 /**
386 * Cookiebot_WP Add debug menu - we need to add this seperate to ensure it is placed last (after menu items from Addons).
387 *
388 * @version 3.6.0
389 * @since 3.6.0
390 */
391 public function add_menu_debug() {
392 add_submenu_page(
393 'cookiebot',
394 __( 'Debug info', 'cookiebot' ),
395 __( 'Debug info', 'cookiebot' ),
396 'manage_options',
397 'cookiebot_debug',
398 array( $this, 'debug_page' )
399 );
400 }
401
402 /**
403 * Cookiebot_WP Add menu for network sites
404 *
405 * @version 2.2.0
406 * @since 2.2.0
407 */
408 public function add_network_menu() {
409 $icon = 'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNzIgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI0ZGRkZGRiIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNNDYuODcyNTkwMyA4Ljc3MzU4MzM0QzQxLjk0MzkwMzkgMy4zODI5NTAxMSAzNC44NDI0OTQ2IDAgMjYuOTQ4MjgxOSAwIDEyLjA2NTE1NjggMCAwIDEyLjAyNDQ3NzQgMCAyNi44NTc0MjE5YzAgMTQuODMyOTQ0NSAxMi4wNjUxNTY4IDI2Ljg1NzQyMTkgMjYuOTQ4MjgxOSAyNi44NTc0MjE5IDcuODk0MjEyNyAwIDE0Ljk5NTYyMi0zLjM4Mjk1MDIgMTkuOTI0MzA4NC04Ljc3MzU4MzQtMi44ODk2OTY3LTEuMzY4ODY2My01LjM5OTMxMS0zLjQwNTQzOS03LjMyODA4MzgtNS45MDk2MzU4LTMuMTIxNDMwNiAzLjIwOTQxMDQtNy40OTI5OTQ0IDUuMjA0MTI5MS0xMi4zMzIwMjU4IDUuMjA0MTI5MS05LjQ4NDM0NDQgMC0xNy4xNzI5MjQ3LTcuNjYyNjU3Mi0xNy4xNzI5MjQ3LTE3LjExNTAyMzhzNy42ODg1ODAzLTE3LjExNTAyMzcgMTcuMTcyOTI0Ny0xNy4xMTUwMjM3YzQuNzIzNDgyMiAwIDkuMDAxNTU1MiAxLjkwMDU5MzkgMTIuMTA2MjkyIDQuOTc2MzA5IDEuOTU2OTIzNy0yLjY0MTEzMSA0LjU1MDAyNjMtNC43ODU1MTgzIDcuNTUzODE3Ni02LjIwODQzMTg2eiIvPjxwYXRoIGQ9Ik01NS4zODAzMjgyIDQyLjY1MDE5OTFDNDYuMzMzNzIyNyA0Mi42NTAxOTkxIDM5IDM1LjM0MTIwMzEgMzkgMjYuMzI1MDk5NiAzOSAxNy4zMDg5OTYgNDYuMzMzNzIyNyAxMCA1NS4zODAzMjgyIDEwYzkuMDQ2NjA1NSAwIDE2LjM4MDMyODIgNy4zMDg5OTYgMTYuMzgwMzI4MiAxNi4zMjUwOTk2IDAgOS4wMTYxMDM1LTcuMzMzNzIyNyAxNi4zMjUwOTk1LTE2LjM4MDMyODIgMTYuMzI1MDk5NXptLjAyMTMwOTItNy43NTU2MzQyYzQuNzM3MDI3NiAwIDguNTc3MTQ3MS0zLjgyNzE3MiA4LjU3NzE0NzEtOC41NDgyMjc5IDAtNC43MjEwNTYtMy44NDAxMTk1LTguNTQ4MjI4LTguNTc3MTQ3MS04LjU0ODIyOC00LjczNzAyNzUgMC04LjU3NzE0NyAzLjgyNzE3Mi04LjU3NzE0NyA4LjU0ODIyOCAwIDQuNzIxMDU1OSAzLjg0MDExOTUgOC41NDgyMjc5IDguNTc3MTQ3IDguNTQ4MjI3OXoiLz48L2c+PC9zdmc+';
410 add_menu_page(
411 'Cookiebot',
412 __( 'Cookiebot', 'cookiebot' ),
413 'manage_network_options',
414 'cookiebot_network',
415 array( $this, 'network_settings_page' ),
416 $icon
417 );
418
419 add_submenu_page(
420 'cookiebot_network',
421 __( 'Cookiebot Settings', 'cookiebot' ),
422 __( 'Settings', 'cookiebot' ),
423 'network_settings_page',
424 'cookiebot_network',
425 array( $this, 'network_settings_page' )
426 );
427 add_submenu_page(
428 'cookiebot_network',
429 __( 'Cookiebot Support', 'cookiebot' ),
430 __( 'Support', 'cookiebot' ),
431 'network_settings_page',
432 'cookiebot_support',
433 array( $this, 'support_page' )
434 );
435
436 }
437
438 /**
439 * Cookiebot_WP Cookiebot prior consent placeholder page
440 *
441 * @version 1.4.0
442 * @since 1.0.0
443 */
444 public function setting_page_placeholder() {
445 include __DIR__ . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'view/admin/settings/setting-page.php';
446 }
447
448 /**
449 * Cookiebot_WP Register Cookiebot settings
450 *
451 * @version 3.9.0
452 * @since 1.0.0
453 */
454 public function register_cookiebot_settings() {
455 register_setting( 'cookiebot', 'cookiebot-cbid' );
456 register_setting( 'cookiebot', 'cookiebot-language' );
457 register_setting( 'cookiebot', 'cookiebot-nooutput' );
458 register_setting( 'cookiebot', 'cookiebot-nooutput-admin' );
459 register_setting( 'cookiebot', 'cookiebot-output-logged-in' );
460 register_setting( 'cookiebot', 'cookiebot-autoupdate' );
461 register_setting( 'cookiebot', 'cookiebot-script-tag-uc-attribute' );
462 register_setting( 'cookiebot', 'cookiebot-script-tag-cd-attribute' );
463 register_setting( 'cookiebot', 'cookiebot-cookie-blocking-mode' );
464 register_setting( 'cookiebot', 'cookiebot-consent-mapping' );
465 register_setting( 'cookiebot-iab', 'cookiebot-iab' );
466 register_setting( 'cookiebot-legislations', 'cookiebot-ccpa' );
467 register_setting( 'cookiebot-legislations', 'cookiebot-ccpa-domain-group-id' );
468 register_setting( 'cookiebot-gtm', 'cookiebot-gtm' );
469 register_setting( 'cookiebot-gtm', 'cookiebot-gtm-id' );
470 register_setting( 'cookiebot-gtm', 'cookiebot-data-layer' );
471 register_setting( 'cookiebot-gtm', 'cookiebot-gcm' );
472 }
473
474 /**
475 * Cookiebot_WP Automatic update plugin if activated
476 *
477 * @version 2.2.0
478 * @since 1.5.0
479 */
480 public function automatic_updates( $update, $item ) {
481 //Do not update from subsite on a multisite installation
482 if ( is_multisite() && ! is_main_site() ) {
483 return $update;
484 }
485
486 //Check if we have everything we need
487 $item = (array) $item;
488 if ( ! isset( $item['new_version'] ) || ! isset( $item['slug'] ) ) {
489 return $update;
490 }
491
492 //It is not Cookiebot
493 if ( $item['slug'] !== 'cookiebot' ) {
494 return $update;
495 }
496
497 // Check if cookiebot autoupdate is disabled
498 if ( ! get_option( 'cookiebot-autoupdate', false ) ) {
499 return $update;
500 }
501
502 // Check if multisite autoupdate is disabled
503 if ( is_multisite() && ! get_site_option( 'cookiebot-autoupdate', false ) ) {
504 return $update;
505 }
506
507 return true;
508 }
509
510
511 /**
512 * Cookiebot_WP Get list of supported languages
513 *
514 * @version 1.4.0
515 * @since 1.4.0
516 */
517 public static function get_supported_languages() {
518 $supported_languages = array();
519 $supported_languages['nb'] = __( 'Norwegian Bokmål', 'cookiebot' );
520 $supported_languages['tr'] = __( 'Turkish', 'cookiebot' );
521 $supported_languages['de'] = __( 'German', 'cookiebot' );
522 $supported_languages['cs'] = __( 'Czech', 'cookiebot' );
523 $supported_languages['da'] = __( 'Danish', 'cookiebot' );
524 $supported_languages['sq'] = __( 'Albanian', 'cookiebot' );
525 $supported_languages['he'] = __( 'Hebrew', 'cookiebot' );
526 $supported_languages['ko'] = __( 'Korean', 'cookiebot' );
527 $supported_languages['it'] = __( 'Italian', 'cookiebot' );
528 $supported_languages['nl'] = __( 'Dutch', 'cookiebot' );
529 $supported_languages['vi'] = __( 'Vietnamese', 'cookiebot' );
530 $supported_languages['ta'] = __( 'Tamil', 'cookiebot' );
531 $supported_languages['is'] = __( 'Icelandic', 'cookiebot' );
532 $supported_languages['ro'] = __( 'Romanian', 'cookiebot' );
533 $supported_languages['si'] = __( 'Sinhala', 'cookiebot' );
534 $supported_languages['ca'] = __( 'Catalan', 'cookiebot' );
535 $supported_languages['bg'] = __( 'Bulgarian', 'cookiebot' );
536 $supported_languages['uk'] = __( 'Ukrainian', 'cookiebot' );
537 $supported_languages['zh'] = __( 'Chinese', 'cookiebot' );
538 $supported_languages['en'] = __( 'English', 'cookiebot' );
539 $supported_languages['ar'] = __( 'Arabic', 'cookiebot' );
540 $supported_languages['hr'] = __( 'Croatian', 'cookiebot' );
541 $supported_languages['th'] = __( 'Thai', 'cookiebot' );
542 $supported_languages['el'] = __( 'Greek', 'cookiebot' );
543 $supported_languages['lt'] = __( 'Lithuanian', 'cookiebot' );
544 $supported_languages['pl'] = __( 'Polish', 'cookiebot' );
545 $supported_languages['lv'] = __( 'Latvian', 'cookiebot' );
546 $supported_languages['fr'] = __( 'French', 'cookiebot' );
547 $supported_languages['id'] = __( 'Indonesian', 'cookiebot' );
548 $supported_languages['mk'] = __( 'Macedonian', 'cookiebot' );
549 $supported_languages['et'] = __( 'Estonian', 'cookiebot' );
550 $supported_languages['pt'] = __( 'Portuguese', 'cookiebot' );
551 $supported_languages['ga'] = __( 'Irish', 'cookiebot' );
552 $supported_languages['ms'] = __( 'Malay', 'cookiebot' );
553 $supported_languages['sl'] = __( 'Slovenian', 'cookiebot' );
554 $supported_languages['ru'] = __( 'Russian', 'cookiebot' );
555 $supported_languages['ja'] = __( 'Japanese', 'cookiebot' );
556 $supported_languages['hi'] = __( 'Hindi', 'cookiebot' );
557 $supported_languages['sk'] = __( 'Slovak', 'cookiebot' );
558 $supported_languages['es'] = __( 'Spanish', 'cookiebot' );
559 $supported_languages['sv'] = __( 'Swedish', 'cookiebot' );
560 $supported_languages['sr'] = __( 'Serbian', 'cookiebot' );
561 $supported_languages['fi'] = __( 'Finnish', 'cookiebot' );
562 $supported_languages['eu'] = __( 'Basque', 'cookiebot' );
563 $supported_languages['hu'] = __( 'Hungarian', 'cookiebot' );
564 asort( $supported_languages, SORT_LOCALE_STRING );
565
566 return $supported_languages;
567 }
568
569 /**
570 * Cookiebot_WP Output settings page
571 *
572 * @version 3.9.0
573 * @since 1.0.0
574 */
575 public function settings_page() {
576 wp_enqueue_style( 'cookiebot-consent-mapping-table', plugins_url( 'css/consent_mapping_table.css', __FILE__ ), array(), '3.5.0' );
577
578 /* Check if multisite */
579 if ( $is_ms = is_multisite() ) {
580 //Receive settings from multisite - this might change the way we render the form
581 $network_cbid = get_site_option( 'cookiebot-cbid', '' );
582 $network_scrip_tag_uc_attr = get_site_option( 'cookiebot-script-tag-uc-attribute', 'custom' );
583 $network_scrip_tag_cd_attr = get_site_option( 'cookiebot-script-tag-cd-attribute', 'custom' );
584 $network_cookie_blocking_mode = get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' );
585 }
586 ?>
587 <div class="wrap">
588 <h1><?php esc_html_e( 'Cookiebot Settings', 'cookiebot' ); ?></h1>
589 <a href="https://www.cookiebot.com">
590 <img src="<?php echo esc_url( plugins_url( 'cookiebot-logo.png', __FILE__ ) ); ?>" style="float:right;margin-left:1em;">
591 </a>
592 <p>
593 <?php
594 $cookiebot_gdpr_url = 'https://www.cookiebot.com/goto/gdpr';
595 printf(
596 esc_html__(
597 '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 %1$s %2$s.',
598 'cookiebot'
599 ),
600 sprintf(
601 '<a href="%s" target="_blank">%s</a>',
602 esc_url( $cookiebot_gdpr_url ),
603 esc_html__( 'General Data Protection Regulation (GDPR)', 'cookiebot' )
604 ),
605 esc_html__(
606 ' 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.',
607 'cookiebot'
608 )
609 );
610 ?>
611 </p>
612 <form method="post" action="options.php">
613 <?php settings_fields( 'cookiebot' ); ?>
614 <?php do_settings_sections( 'cookiebot' ); ?>
615 <table class="form-table">
616 <tr valign="top">
617 <th scope="row"><?php esc_html_e( 'Cookiebot ID', 'cookiebot' ); ?></th>
618 <td>
619 <input
620 type="text"
621 name="cookiebot-cbid"
622 value="<?php echo esc_attr( get_option( 'cookiebot-cbid' ) ); ?>"
623 <?php if ( $is_ms ) : ?>
624 placeholder="<?php echo esc_attr( $network_cbid ); ?>"
625 <?php endif; ?>
626 style="width:300px"
627 />
628 <p class="description">
629 <?php esc_html_e( 'Need an ID?', 'cookiebot' ); ?>
630 <a href="https://www.cookiebot.com/goto/signup" target="_blank">
631 <?php
632 esc_html_e(
633 'Sign up for free on cookiebot.com',
634 'cookiebot'
635 );
636 ?>
637 </a>
638 </p>
639 </td>
640 </tr>
641 <tr valign="top">
642 <th scope="row">
643 <?php esc_html_e( 'Cookie-blocking mode', 'cookiebot' ); ?>
644 </th>
645 <td>
646 <?php
647 $cbm = get_option( 'cookiebot-cookie-blocking-mode', 'manual' );
648 if ( $is_ms && $network_cookie_blocking_mode != 'custom' ) {
649 $cbm = $network_cookie_blocking_mode;
650 }
651 ?>
652 <label>
653 <input type="radio" name="cookiebot-cookie-blocking-mode" value="auto" <?php checked( 'auto', $cbm, true ); ?> />
654 <?php esc_html_e( 'Automatic', 'cookiebot' ); ?>
655 </label>
656 &nbsp; &nbsp;
657 <label>
658 <input type="radio" name="cookiebot-cookie-blocking-mode" value="manual" <?php checked( 'manual', $cbm, true ); ?> />
659 <?php esc_html_e( 'Manual', 'cookiebot' ); ?>
660 </label>
661 <p class="description">
662 <?php esc_html_e( 'Automatic block cookies (except necessary) until the user has given their consent.', 'cookiebot' ); ?>
663 <a href="https://support.cookiebot.com/hc/en-us/articles/360009063100-Automatic-Cookie-Blocking-How-does-it-work-"
664 target="_blank">
665 <?php esc_html_e( 'Learn more', 'cookiebot' ); ?>
666 </a>
667 </p>
668 <script>
669 jQuery( document ).ready( function ( $ ) {
670 var cookieBlockingMode = '<?php echo esc_js( $cbm ); ?>';
671 $( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function () {
672 if ( this.value == 'auto' && cookieBlockingMode != this.value ) {
673 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
674 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
675 }
676 if ( this.value == 'manual' && cookieBlockingMode != this.value ) {
677 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 );
678 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false );
679 }
680 cookieBlockingMode = this.value;
681 } );
682 if ( cookieBlockingMode == 'auto' ) {
683 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
684 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
685 }
686 } );
687 </script>
688 </td>
689 </tr>
690 <tr valign="top">
691 <th scope="row"><?php esc_html_e( 'Cookiebot Language', 'cookiebot' ); ?></th>
692 <td>
693 <div>
694 <select name="cookiebot-language" id="cookiebot-language">
695 <?php
696 $current_lang = $this->get_language( true );
697 ?>
698 <option value=""><?php esc_html_e( 'Default (Autodetect)', 'cookiebot' ); ?></option>
699 <option value="_wp"<?php echo ( $current_lang == '_wp' ) ? ' selected' : ''; ?>>
700 <?php
701 esc_html_e(
702 'Use WordPress Language',
703 'cookiebot'
704 );
705 ?>
706 </option>
707 <?php
708 $supported_languages = $this->get_supported_languages();
709 foreach ( $supported_languages as $lang_code => $lang_name ) :
710 ?>
711 <option value="<?php echo esc_attr( $lang_code ); ?>"
712 <?php if ( $current_lang === $lang_code ) : ?>
713 selected
714 <?php endif; ?>
715 ><?php echo esc_html( $lang_name ); ?></option>
716 <?php endforeach; ?>
717 </select>
718 </div>
719 <div class="notice inline notice-warning notice-alt cookiebot-notice" style="padding:12px;font-size:13px;display:inline-block;">
720 <div style="<?php echo ( $current_lang === '' ) ? 'display:none;' : ''; ?>" id="info_lang_specified">
721 <?php esc_html_e( 'You need to add the language in the Cookiebot administration tool.', 'cookiebot' ); ?>
722 </div>
723 <div style="<?php echo ( $current_lang === '' ) ? '' : 'display:none;'; ?>" id="info_lang_autodetect">
724 <?php
725 esc_html_e(
726 'You need to add all languages that you want auto-detected in the Cookiebot administration tool.',
727 'cookiebot'
728 );
729 ?>
730 <br/>
731 <?php
732 esc_html_e(
733 'The auto-detect checkbox needs to be enabled in the Cookiebot administration tool.',
734 'cookiebot'
735 );
736 ?>
737 <br/>
738 <?php
739 esc_html_e(
740 'If the auto-detected language is not supported, Cookiebot will use the default language.',
741 'cookiebot'
742 );
743 ?>
744 </div>
745 <br/>
746
747 <a href="#" id="show_add_language_guide"><?php esc_html_e( 'Show guide to add languages', 'cookiebot' ); ?></a>
748 &nbsp;
749 <a href="https://support.cookiebot.com/hc/en-us/articles/360003793394-How-do-I-set-the-language-of-the-consent-banner-dialog-"
750 target="_blank">
751 <?php esc_html_e( 'Read more here', 'cookiebot' ); ?>
752 </a>
753
754 <div id="add_language_guide" style="display:none;">
755 <img src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/guide_add_language.gif' ); ?>"
756 alt="Add language in Cookiebot administration tool"/>
757 <br/>
758 <a href="#" id="hide_add_language_guide"><?php esc_html_e( 'Hide guide', 'cookiebot' ); ?></a>
759 </div>
760 </div>
761 <script>
762 jQuery( document ).ready( function ( $ ) {
763 $( '#show_add_language_guide' ).on( 'click', function ( e ) {
764 e.preventDefault();
765 $( '#add_language_guide' ).slideDown();
766 $( this ).hide();
767 } );
768 $( '#hide_add_language_guide' ).on( 'click', function ( e ) {
769 e.preventDefault();
770 $( '#add_language_guide' ).slideUp();
771 $( '#show_add_language_guide' ).show();
772 } );
773
774 $( '#cookiebot-language' ).on( 'change', function () {
775 if ( this.value === '' ) {
776 $( '#info_lang_autodetect' ).show();
777 $( '#info_lang_specified' ).hide();
778 } else {
779 $( '#info_lang_autodetect' ).hide();
780 $( '#info_lang_specified' ).show();
781 }
782 } );
783 } );
784 </script>
785
786 </td>
787 </tr>
788 </table>
789 <script>
790 jQuery( document ).ready( function ( $ ) {
791 $( '.cookiebot_fieldset_header' ).on( 'click', function ( e ) {
792 e.preventDefault();
793 $( this ).next().slideToggle();
794 $( this ).toggleClass( 'active' );
795 } );
796 } );
797 </script>
798 <style type="text/css">
799 .cookiebot_fieldset_header {
800 cursor: pointer;
801 }
802
803 .cookiebot_fieldset_header::after {
804 content: "\f140";
805 font: normal 24px/1 dashicons;
806 position: relative;
807 top: 5px;
808 }
809
810 .cookiebot_fieldset_header.active::after {
811 content: "\f142";
812 }
813 </style>
814 <h3 id="advanced_settings_link" class="cookiebot_fieldset_header"><?php esc_html_e( 'Advanced settings', 'cookiebot' ); ?></h3>
815 <div id="advanced_settings" style="display:none;">
816 <table class="form-table">
817 <tr valign="top" id="cookiebot-setting-async">
818 <th scope="row">
819 <?php esc_html_e( 'Add async or defer attribute', 'cookiebot' ); ?>
820 <br/><?php esc_html_e( 'Consent banner script tag', 'cookiebot' ); ?>
821 </th>
822 <td>
823 <?php
824 $cv = get_option( 'cookiebot-script-tag-uc-attribute', 'async' );
825 $disabled = false;
826 if ( $is_ms && $network_scrip_tag_uc_attr !== 'custom' ) {
827 $disabled = true;
828 $cv = $network_scrip_tag_uc_attr;
829 }
830 ?>
831 <label>
832 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
833 value="" <?php checked( '', $cv, true ); ?> />
834 <i><?php esc_html_e( 'None', 'cookiebot' ); ?></i>
835 </label>
836 &nbsp; &nbsp;
837 <label>
838 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
839 value="async" <?php checked( 'async', $cv, true ); ?> />
840 async
841 </label>
842 &nbsp; &nbsp;
843 <label>
844 <input type="radio" name="cookiebot-script-tag-uc-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
845 value="defer" <?php checked( 'defer', $cv, true ); ?> />
846 defer
847 </label>
848 <p class="description">
849 <?php
850 if ( $disabled ) {
851 echo '<b>' . esc_html__(
852 'Network setting applied. Please contact website administrator to change this setting.',
853 'cookiebot'
854 ) . '</b><br />';
855 }
856 ?>
857 <?php esc_html_e( 'Add async or defer attribute to Cookiebot script tag. Default: async', 'cookiebot' ); ?>
858 </p>
859 </td>
860 </tr>
861 <tr valign="top">
862 <th scope="row">
863 <?php esc_html_e( 'Add async or defer attribute', 'cookiebot' ); ?>
864 <br/><?php esc_html_e( 'Cookie declaration script tag', 'cookiebot' ); ?>
865 </th>
866 <td>
867 <?php
868 $cv = get_option( 'cookiebot-script-tag-cd-attribute', 'async' );
869 $disabled = false;
870 if ( $is_ms && $network_scrip_tag_cd_attr !== 'custom' ) {
871 $disabled = true;
872 $cv = $network_scrip_tag_cd_attr;
873 }
874 ?>
875 <label>
876 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
877 value="" <?php checked( '', $cv, true ); ?> />
878 <i><?php esc_html_e( 'None', 'cookiebot' ); ?></i>
879 </label>
880 &nbsp; &nbsp;
881 <label>
882 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
883 value="async" <?php checked( 'async', $cv, true ); ?> />
884 async
885 </label>
886 &nbsp; &nbsp;
887 <label>
888 <input type="radio" name="cookiebot-script-tag-cd-attribute"<?php echo ( $disabled ) ? ' disabled' : ''; ?>
889 value="defer" <?php checked( 'defer', $cv, true ); ?> />
890 defer
891 </label>
892 <p class="description">
893 <?php
894 if ( $disabled ) {
895 echo '<b>' . esc_html__(
896 'Network setting applied. Please contact website administrator to change this setting.',
897 'cookiebot'
898 ) . '</b><br />';
899 }
900 ?>
901 <?php esc_html_e( 'Add async or defer attribute to Cookiebot script tag. Default: async', 'cookiebot' ); ?>
902 </p>
903 </td>
904 </tr>
905 <?php
906 if ( ! is_multisite() ) {
907 ?>
908 <tr valign="top">
909 <th scope="row"><?php esc_html_e( 'Auto-update Cookiebot', 'cookiebot' ); ?></th>
910 <td>
911 <input type="checkbox" name="cookiebot-autoupdate" value="1"
912 <?php
913 checked(
914 1,
915 get_option( 'cookiebot-autoupdate', false ),
916 true
917 );
918 ?>
919 />
920 <p class="description">
921 <?php esc_html_e( 'Automatic update your Cookiebot plugin when new releases becomes available.', 'cookiebot' ); ?>
922 </p>
923 </td>
924 </tr>
925 <?php
926 }
927 ?>
928 <tr valign="top" id="cookiebot-setting-hide-popup">
929 <th scope="row"><?php esc_html_e( 'Hide Cookie Popup', 'cookiebot' ); ?></th>
930 <td>
931 <?php
932 $disabled = false;
933 if ( $is_ms && get_site_option( 'cookiebot-nooutput', false ) ) {
934 $disabled = true;
935 echo '<input type="checkbox" checked disabled />';
936 } else {
937 ?>
938 <input type="checkbox" name="cookiebot-nooutput" value="1"
939 <?php
940 checked(
941 1,
942 get_option( 'cookiebot-nooutput', false ),
943 true
944 );
945 ?>
946 />
947 <?php
948 }
949 ?>
950 <p class="description">
951 <?php
952 if ( $disabled ) {
953 echo '<b>' . esc_html__(
954 'Network setting applied. Please contact website administrator to change this setting.',
955 'cookiebot'
956 ) . '</b><br />';
957 }
958 ?>
959 <b>
960 <?php
961 esc_html_e(
962 'This checkbox will remove the cookie consent banner from your website. The <i>[cookie_declaration]</i> shortcode will still be available.',
963 'cookiebot'
964 );
965 ?>
966 </b><br/>
967 <?php
968 esc_html_e(
969 'If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.',
970 'cookiebot'
971 );
972 ?>
973 <br/>
974 <a href="https://support.cookiebot.com/hc/en-us/articles/360003793854-Google-Tag-Manager-deployment" target="_blank">
975 <?php esc_html_e( 'See a detailed guide here', 'cookiebot' ); ?>
976 </a>
977 </p>
978 </td>
979 </tr>
980 <tr valign="top">
981 <th scope="row"><?php esc_html_e( 'Disable Cookiebot in WP Admin', 'cookiebot' ); ?></th>
982 <td>
983 <?php
984 $disabled = false;
985 if ( $is_ms && get_site_option( 'cookiebot-nooutput-admin', false ) ) {
986 echo '<input type="checkbox" checked disabled />';
987 $disabled = true;
988 } else {
989 ?>
990 <input type="checkbox" name="cookiebot-nooutput-admin" value="1"
991 <?php
992 checked(
993 1,
994 get_option( 'cookiebot-nooutput-admin', false ),
995 true
996 );
997 ?>
998 />
999 <?php
1000 }
1001 ?>
1002 <p class="description">
1003 <?php
1004 if ( $disabled ) {
1005 echo '<b>' . esc_html__( 'Network setting applied. Please contact website administrator to change this setting.' ) . '</b><br />';
1006 }
1007 ?>
1008 <b><?php esc_html_e( 'This checkbox will disable Cookiebot in the WordPress Admin area.', 'cookiebot' ); ?></b>
1009 </p>
1010 </td>
1011 </tr>
1012 <tr valign="top">
1013 <th scope="row"><?php esc_html_e( 'Enable Cookiebot on front end while logged in', 'cookiebot' ); ?></th>
1014 <td>
1015 <?php
1016 $disabled = false;
1017 if ( $is_ms && get_site_option( 'cookiebot-output-logged-in', false ) ) {
1018 echo '<input type="checkbox" checked disabled />';
1019 $disabled = true;
1020 } else {
1021 ?>
1022 <input type="checkbox" name="cookiebot-output-logged-in" value="1"
1023 <?php
1024 checked(
1025 1,
1026 get_option( 'cookiebot-output-logged-in', false ),
1027 true
1028 );
1029 ?>
1030 />
1031 <?php
1032 }
1033 ?>
1034 <p class="description">
1035 <?php
1036 if ( $disabled ) {
1037 echo '<b>' . esc_html__( 'Network setting applied. Please contact website administrator to change this setting.' ) . '</b><br />';
1038 }
1039 ?>
1040 <b><?php esc_html_e( 'This checkbox will enable Cookiebot on front end while you\'re logged in', 'cookiebot' ); ?></b>
1041 </p>
1042 </td>
1043 </tr>
1044 </table>
1045 </div>
1046 <?php if ( $this->is_wp_consent_api_active() ) { ?>
1047 <h3 id="consent_level_api_settings" class="cookiebot_fieldset_header">
1048 <?php
1049 esc_html_e(
1050 'Consent Level API Settings',
1051 'cookiebot'
1052 );
1053 ?>
1054 </h3>
1055 <div id="consent_level_api_settings" style="display:none;">
1056 <p>
1057 <?php
1058 esc_html_e(
1059 'WP Consent Level API and Cookiebot categorise cookies a bit different. The default settings should fit mosts needs - but if you need to change the mapping you are able to do it below.',
1060 'cookiebot'
1061 );
1062 ?>
1063 </p>
1064
1065 <?php
1066 $mDefault = $this->get_default_wp_consent_api_mapping();
1067
1068 $m = $this->get_wp_consent_api_mapping();
1069
1070 $consentTypes = array( 'preferences', 'statistics', 'marketing' );
1071 $states = array_reduce(
1072 $consentTypes,
1073 function ( $t, $v ) {
1074 $newt = array();
1075 if ( empty( $t ) ) {
1076 $newt = array(
1077 array( $v => true ),
1078 array( $v => false ),
1079 );
1080 } else {
1081 foreach ( $t as $item ) {
1082 $newt[] = array_merge( $item, array( $v => true ) );
1083 $newt[] = array_merge( $item, array( $v => false ) );
1084 }
1085 }
1086
1087 return $newt;
1088 },
1089 array()
1090 );
1091
1092 ?>
1093
1094
1095 <table class="widefat striped consent_mapping_table">
1096 <thead>
1097 <tr>
1098 <th><?php esc_html_e( 'Cookiebot categories', 'cookiebot' ); ?></th>
1099 <th class="consent_mapping"><?php esc_html_e( 'WP Consent Level categories', 'cookiebot' ); ?></th>
1100 </tr>
1101 </thead>
1102 <?php
1103 foreach ( $states as $state ) {
1104
1105 $key = array();
1106 $key[] = 'n=1';
1107 $key[] = 'p=' . ( $state['preferences'] ? '1' : '0' );
1108 $key[] = 's=' . ( $state['statistics'] ? '1' : '0' );
1109 $key[] = 'm=' . ( $state['marketing'] ? '1' : '0' );
1110 $key = implode( ';', $key );
1111 ?>
1112 <tr valign="top">
1113 <td>
1114 <div class="cb_consent">
1115 <span class="forceconsent">
1116 <?php esc_html_e( 'Necessary', 'cookiebot' ); ?>
1117 </span>
1118 <span class="<?php echo( $state['preferences'] ? 'consent' : 'noconsent' ); ?>">
1119 <?php esc_html_e( 'Preferences', 'cookiebot' ); ?>
1120 </span>
1121 <span class="<?php echo( $state['statistics'] ? 'consent' : 'noconsent' ); ?>">
1122 <?php esc_html_e( 'Statistics', 'cookiebot' ); ?>
1123 </span>
1124 <span class="<?php echo( $state['marketing'] ? 'consent' : 'noconsent' ); ?>">
1125 <?php esc_html_e( 'Marketing', 'cookiebot' ); ?>
1126 </span>
1127 </div>
1128 </td>
1129 <td>
1130 <div class="consent_mapping">
1131 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo esc_attr( $key ); ?>][functional]"
1132 data-default-value="1" value="1" checked disabled
1133 > <?php esc_html_e( 'Functional', 'cookiebot' ); ?> </label>
1134 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo esc_attr( $key ); ?>][preferences]"
1135 data-default-value="<?php echo esc_attr( $mDefault[ $key ]['preferences'] ); ?>" value="1"
1136 <?php
1137 if ( $m[ $key ]['preferences'] ) {
1138 echo 'checked';
1139 }
1140 ?>
1141 > <?php esc_html_e( 'Preferences', 'cookiebot' ); ?> </label>
1142 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo esc_attr( $key ); ?>][statistics]"
1143 data-default-value="<?php echo esc_attr( $mDefault[ $key ]['statistics'] ); ?>" value="1"
1144 <?php
1145 if ( $m[ $key ]['statistics'] ) {
1146 echo 'checked';
1147 }
1148 ?>
1149 > <?php esc_html_e( 'Statistics', 'cookiebot' ); ?> </label>
1150 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo esc_attr( $key ); ?>][statistics-anonymous]"
1151 data-default-value="<?php echo esc_attr( $mDefault[ $key ]['statistics-anonymous'] ); ?>" value="1"
1152 <?php
1153 if ( $m[ $key ]['statistics-anonymous'] ) {
1154 echo 'checked';
1155 }
1156 ?>
1157 > <?php esc_html_e( 'Statistics Anonymous', 'cookiebot' ); ?></label>
1158 <label><input type="checkbox" name="cookiebot-consent-mapping[<?php echo esc_attr( $key ); ?>][marketing]"
1159 data-default-value="<?php echo esc_attr( $mDefault[ $key ]['marketing'] ); ?>" value="1"
1160 <?php
1161 if ( $m[ $key ]['marketing'] ) {
1162 echo 'checked';
1163 }
1164 ?>
1165 > <?php esc_html_e( 'Marketing', 'cookiebot' ); ?></label>
1166 </div>
1167 </td>
1168 </tr>
1169 <?php
1170 }
1171 ?>
1172 <tfoot>
1173 <tr>
1174 <td colspan="2" style="text-align:right;">
1175 <button class="button" onclick="return resetConsentMapping();">
1176 <?php
1177 esc_html_e(
1178 'Reset to default mapping',
1179 'cookiebot'
1180 );
1181 ?>
1182 </button>
1183 </td>
1184 </tr>
1185 </tfoot>
1186 </table>
1187 <script>
1188 function resetConsentMapping() {
1189 if ( confirm( 'Are you sure you want to reset to default consent mapping?' ) ) {
1190 jQuery( '.consent_mapping_table input[type=checkbox]' ).each( function () {
1191 if ( !this.disabled ) {
1192 this.checked = ( jQuery( this ).data( 'default-value' ) == '1' ) ? true : false;
1193 }
1194 } );
1195 }
1196 return false;
1197 }
1198 </script>
1199 </div>
1200 <?php } ?>
1201 <?php submit_button(); ?>
1202 </form>
1203 </div>
1204 <?php
1205 }
1206
1207 /**
1208 * Cookiebot_WP Cookiebot network setting page
1209 *
1210 * @version 2.2.0
1211 * @since 2.2.0
1212 */
1213 public function network_settings_page() {
1214 ?>
1215 <div class="wrap">
1216 <h1><?php esc_html_e( 'Cookiebot Network Settings', 'cookiebot' ); ?></h1>
1217 <a href="https://www.cookiebot.com">
1218 <img src="<?php echo esc_url( plugins_url( 'cookiebot-logo.png', __FILE__ ) ); ?>" style="float:right;margin-left:1em;">
1219 </a>
1220 <p>
1221 <?php
1222 $cookiebot_gdpr_url = 'https://www.cookiebot.com/goto/gdpr';
1223 printf(
1224 esc_html__(
1225 '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 %1$s %2$s.',
1226 'cookiebot'
1227 ),
1228 sprintf(
1229 '<a href="%s" target="_blank">%s</a>',
1230 esc_url( $cookiebot_gdpr_url ),
1231 esc_html__( 'General Data Protection Regulation (GDPR)', 'cookiebot' )
1232 ),
1233 esc_html__(
1234 ' 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.',
1235 'cookiebot'
1236 )
1237 );
1238 ?>
1239 </p>
1240 <p>
1241 <b><big style="color:red;">
1242 <?php
1243 esc_html_e(
1244 'The settings below is network wide settings. See notes below each field.',
1245 'cookiebot'
1246 );
1247 ?>
1248 </big></b>
1249 </p>
1250 <form method="post" action="edit.php?action=cookiebot_network_settings">
1251 <?php wp_nonce_field( 'cookiebot-network-settings' ); ?>
1252 <table class="form-table">
1253 <tr valign="top">
1254 <th scope="row"><?php esc_html_e( 'Network Cookiebot ID', 'cookiebot' ); ?></th>
1255 <td>
1256 <input type="text" name="cookiebot-cbid" value="<?php echo esc_attr( get_site_option( 'cookiebot-cbid', '' ) ); ?>"
1257 style="width:300px"/>
1258 <p class="description">
1259 <b>
1260 <?php
1261 esc_html_e(
1262 'If added this will be the default Cookiebot ID for all subsites. Subsites are able to override the Cookiebot ID.',
1263 'cookiebot'
1264 );
1265 ?>
1266 </b>
1267 <br/>
1268 <?php esc_html_e( 'Need an ID?', 'cookiebot' ); ?>
1269 <a href="https://www.cookiebot.com/goto/signup" target="_blank">
1270 <?php
1271 esc_html_e(
1272 'Sign up for free on cookiebot.com',
1273 'cookiebot'
1274 );
1275 ?>
1276 </a>
1277 </p>
1278 </td>
1279 </tr>
1280 <tr valign="top">
1281 <th scope="row">
1282 <?php esc_html_e( 'Cookie-blocking mode', 'cookiebot' ); ?>
1283 </th>
1284 <td>
1285 <?php
1286 $cbm = get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' );
1287 ?>
1288 <label>
1289 <input type="radio" name="cookiebot-cookie-blocking-mode" value="auto" <?php checked( 'auto', $cbm, true ); ?> />
1290 <?php esc_html_e( 'Automatic', 'cookiebot' ); ?>
1291 </label>
1292 &nbsp; &nbsp;
1293 <label>
1294 <input type="radio" name="cookiebot-cookie-blocking-mode" value="manual" <?php checked( 'manual', $cbm, true ); ?> />
1295 <?php esc_html_e( 'Manual', 'cookiebot' ); ?>
1296 </label>
1297 <p class="description">
1298 <?php esc_html_e( 'Should Cookiebot automatic block cookies by tagging known tags.', 'cookiebot' ); ?>
1299 </p>
1300 </td>
1301 </tr>
1302 <script>
1303 jQuery( document ).ready( function ( $ ) {
1304 var cookieBlockingMode = '<?php echo esc_js( $cbm ); ?>';
1305 $( 'input[type=radio][name=cookiebot-cookie-blocking-mode]' ).on( 'change', function () {
1306 if ( this.value == 'auto' && cookieBlockingMode != this.value ) {
1307 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
1308 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
1309 }
1310 if ( this.value == 'manual' && cookieBlockingMode != this.value ) {
1311 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 1 );
1312 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', false );
1313 }
1314 cookieBlockingMode = this.value;
1315 } );
1316 if ( cookieBlockingMode == 'auto' ) {
1317 $( '#cookiebot-setting-async, #cookiebot-setting-hide-popup' ).css( 'opacity', 0.4 );
1318 $( 'input[type=radio][name=cookiebot-script-tag-uc-attribute], input[name=cookiebot-nooutput]' ).prop( 'disabled', true );
1319 }
1320 } );
1321 </script>
1322 <tr valign="top" id="cookiebot-setting-async">
1323 <th scope="row">
1324 <?php esc_html_e( 'Add async or defer attribute', 'cookiebot' ); ?>
1325 <br/><?php esc_html_e( 'Consent banner script tag', 'cookiebot' ); ?>
1326 </th>
1327 <td>
1328 <?php
1329 $cv = get_site_option( 'cookiebot-script-tag-uc-attribute', 'custom' );
1330 ?>
1331 <label>
1332 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="" <?php checked( '', $cv, true ); ?> />
1333 <i><?php esc_html_e( 'None', 'cookiebot' ); ?></i>
1334 </label>
1335 &nbsp; &nbsp;
1336 <label>
1337 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="async" <?php checked( 'async', $cv, true ); ?> />
1338 async
1339 </label>
1340 &nbsp; &nbsp;
1341 <label>
1342 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="defer" <?php checked( 'defer', $cv, true ); ?> />
1343 defer
1344 </label>
1345 &nbsp; &nbsp;
1346 <label>
1347 <input type="radio" name="cookiebot-script-tag-uc-attribute" value="custom" <?php checked( 'custom', $cv, true ); ?> />
1348 <i><?php esc_html_e( 'Choose per subsite', 'cookiebot' ); ?></i>
1349 </label>
1350 <p class="description">
1351 <b>
1352 <?php
1353 esc_html_e(
1354 'Setting will apply for all subsites. Subsites will not be able to override.',
1355 'cookiebot'
1356 );
1357 ?>
1358 </b><br/>
1359 <?php esc_html_e( 'Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite', 'cookiebot' ); ?>
1360 </p>
1361 </td>
1362 </tr>
1363 <tr valign="top">
1364 <th scope="row">
1365 <?php esc_html_e( 'Add async or defer attribute', 'cookiebot' ); ?>
1366 <br/><?php esc_html_e( 'Cookie declaration script tag', 'cookiebot' ); ?>
1367 </th>
1368 <td>
1369 <?php
1370 $cv = get_site_option( 'cookiebot-script-tag-cd-attribute', 'custom' );
1371 ?>
1372 <label>
1373 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="" <?php checked( '', $cv, true ); ?> />
1374 <i><?php esc_html_e( 'None', 'cookiebot' ); ?></i>
1375 </label>
1376 &nbsp; &nbsp;
1377 <label>
1378 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="async" <?php checked( 'async', $cv, true ); ?> />
1379 async
1380 </label>
1381 &nbsp; &nbsp;
1382 <label>
1383 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="defer" <?php checked( 'defer', $cv, true ); ?> />
1384 defer
1385 </label>
1386 &nbsp; &nbsp;
1387 <label>
1388 <input type="radio" name="cookiebot-script-tag-cd-attribute" value="custom" <?php checked( 'custom', $cv, true ); ?> />
1389 <i><?php esc_html_e( 'Choose per subsite', 'cookiebot' ); ?></i>
1390 </label>
1391 <p class="description">
1392 <b>
1393 <?php
1394 esc_html_e(
1395 'Setting will apply for all subsites. Subsites will not be able to override.',
1396 'cookiebot'
1397 );
1398 ?>
1399 </b><br/>
1400 <?php esc_html_e( 'Add async or defer attribute to Cookiebot script tag. Default: Choose per subsite', 'cookiebot' ); ?>
1401 </p>
1402 </td>
1403 </tr>
1404 <tr valign="top">
1405 <th scope="row"><?php esc_html_e( 'Auto-update Cookiebot', 'cookiebot' ); ?></th>
1406 <td>
1407 <input type="checkbox" name="cookiebot-autoupdate" value="1"
1408 <?php
1409 checked(
1410 1,
1411 get_site_option( 'cookiebot-autoupdate', false ),
1412 true
1413 );
1414 ?>
1415 />
1416 <p class="description">
1417 <?php esc_html_e( 'Automatic update your Cookiebot plugin when new releases becomes available.', 'cookiebot' ); ?>
1418 </p>
1419 </td>
1420 </tr>
1421 <tr valign="top" id="cookiebot-setting-hide-popup">
1422 <th scope="row"><?php esc_html_e( 'Hide Cookie Popup', 'cookiebot' ); ?></th>
1423 <td>
1424 <input type="checkbox" name="cookiebot-nooutput" value="1"
1425 <?php
1426 checked(
1427 1,
1428 get_site_option( 'cookiebot-nooutput', false ),
1429 true
1430 );
1431 ?>
1432 />
1433 <p class="description">
1434 <b>
1435 <?php
1436 esc_html_e(
1437 'Remove the cookie consent banner from all subsites. This cannot be changed by subsites. The <i>[cookie_declaration]</i> shortcode will still be available.',
1438 'cookiebot'
1439 );
1440 ?>
1441 </b><br/>
1442 <?php
1443 esc_html_e(
1444 'If you are using Google Tag Manager (or equal), you need to add the Cookiebot script in your Tag Manager.',
1445 'cookiebot'
1446 );
1447 ?>
1448 <br/>
1449 <?php
1450 esc_html_e(
1451 '<a href="https://support.cookiebot.com/hc/en-us/articles/360003793854-Google-Tag-Manager-deployment" target="_blank">See a detailed guide here</a>',
1452 'cookiebot'
1453 );
1454 ?>
1455 </p>
1456 </td>
1457 </tr>
1458 <tr valign="top">
1459 <th scope="row"><?php esc_html_e( 'Hide Cookie Popup in WP Admin', 'cookiebot' ); ?></th>
1460 <td>
1461 <input type="checkbox" name="cookiebot-nooutput-admin" value="1"
1462 <?php
1463 checked(
1464 1,
1465 get_site_option( 'cookiebot-nooutput-admin', false ),
1466 true
1467 );
1468 ?>
1469 />
1470 <p class="description">
1471 <b>
1472 <?php
1473 esc_html_e(
1474 'Remove the cookie consent banner the WordPress Admin area for all subsites. This cannot be changed by subsites.',
1475 'cookiebot'
1476 );
1477 ?>
1478 </b>
1479 </p>
1480 </td>
1481 </tr>
1482 </table>
1483 <?php submit_button(); ?>
1484 </form>
1485 </div>
1486 <?php
1487 }
1488
1489
1490 /**
1491 * Cookiebot_WP Cookiebot save network settings
1492 *
1493 * @version 2.2.0
1494 * @since 2.2.0
1495 */
1496 public function network_settings_save() {
1497 check_admin_referer( 'cookiebot-network-settings' );
1498
1499 update_site_option( 'cookiebot-cbid', $_POST['cookiebot-cbid'] );
1500 update_site_option( 'cookiebot-script-tag-uc-attribute', $_POST['cookiebot-script-tag-uc-attribute'] );
1501 update_site_option( 'cookiebot-script-tag-cd-attribute', $_POST['cookiebot-script-tag-cd-attribute'] );
1502 update_site_option( 'cookiebot-autoupdate', $_POST['cookiebot-autoupdate'] );
1503 update_site_option( 'cookiebot-nooutput', $_POST['cookiebot-nooutput'] );
1504 update_site_option( 'cookiebot-nooutput-admin', $_POST['cookiebot-nooutput-admin'] );
1505 update_site_option( 'cookiebot-cookie-blocking-mode', $_POST['cookiebot-cookie-blocking-mode'] );
1506
1507 wp_redirect(
1508 add_query_arg(
1509 array(
1510 'page' => 'cookiebot_network',
1511 'updated' => true,
1512 ),
1513 network_admin_url( 'admin.php' )
1514 )
1515 );
1516 exit;
1517 }
1518
1519 /**
1520 * Cookiebot_WP Cookiebot support page
1521 *
1522 * @version 2.2.0
1523 * @since 2.0.0
1524 */
1525 public function support_page() {
1526 ?>
1527 <div class="wrap">
1528 <h1><?php esc_html_e( 'Support', 'cookiebot' ); ?></h1>
1529 <h2><?php esc_html_e( 'How to find my Cookiebot ID', 'cookiebot' ); ?></h2>
1530 <div>
1531 <ol>
1532 <li>
1533 <?php
1534 echo sprintf(
1535 // translators: the first placeholder string will be replaced with a html anchor open tag and the second placeholder string will be replaced by the html anchor closing tag
1536 esc_html__( 'Log in to your %1$sCookiebot account%2$s.', 'cookiebot' ),
1537 '<a href="https://www.cookiebot.com/goto/account" target="_blank">',
1538 '</a>'
1539 );
1540 ?>
1541 </li>
1542 <li>
1543 <?php
1544 echo sprintf(
1545 // translators: the placeholder strings denote the positions of <b>, </b>, <b> and </b> HTML tags
1546 esc_html__( 'Go to %1$sManage%2$s > %3$sSettings%4$s and add setup your Cookiebot', 'cookiebot' ),
1547 '<b>',
1548 '</b>',
1549 '<b>',
1550 '</b>'
1551 );
1552 ?>
1553 </li>
1554 <li>
1555 <?php
1556 echo sprintf(
1557 // translators: the placeholder strings denote the positions of <b> and </b> HTML tags
1558 esc_html__( 'Go to the %1$s"Your scripts"%2$s tab', 'cookiebot' ),
1559 '<b>',
1560 '</b>'
1561 );
1562 ?>
1563 </li>
1564 <li><?php esc_html_e( 'Copy the value inside the data-cid parameter - eg.: abcdef12-3456-7890-abcd-ef1234567890', 'cookiebot' ); ?></li>
1565 <li>
1566 <?php
1567 echo sprintf(
1568 // translators: the placeholder strings denote the positions of <b> and </b> HTML tags
1569 esc_html__( 'Add %1$s[cookie_declaration]%2$s shortcode to a page to show the declation', 'cookiebot' ),
1570 '<b>',
1571 '</b>'
1572 );
1573 ?>
1574 </li>
1575 <li><?php esc_html_e( 'Remember to change your scripts as descripted below', 'cookiebot' ); ?></li>
1576 </ol>
1577 </div>
1578 <h2><?php esc_html_e( 'Add the Cookie Declaration to your website', 'cookiebot' ); ?></h2>
1579 <p>
1580 <?php
1581 echo sprintf(
1582 // translators: the placeholder strings denote the positions of <b> and </b> HTML tags
1583 esc_html__( 'Use the shortcode %1$s[cookie_declaration]%2$s to add the cookie declaration a page or post. The cookie declaration will always show the latest version from Cookiebot.', 'cookiebot' ),
1584 '<b>',
1585 '</b>'
1586 );
1587 ?>
1588 <br/>
1589 <?php
1590 echo sprintf(
1591 // translators: the placeholder strings denote the positions of <i>, </i>, <b> and </b> HTML tags
1592 esc_html__( 'If you need to force language of the cookie declaration, you can add the %1$slang%2$s attribute. Eg. %3$s[cookie_declaration lang="de"]%4$s.', 'cookiebot' ),
1593 '<i>',
1594 '</i>',
1595 '<b>',
1596 '</b>'
1597 );
1598 ?>
1599 </p>
1600 <p>
1601 <a href="https://www.youtube.com/watch?v=OCXz2bt4H_w" target="_blank" class="button">
1602 <?php
1603 esc_html_e(
1604 'Watch video demonstration',
1605 'cookiebot'
1606 );
1607 ?>
1608 </a>
1609 </p>
1610 <h2><?php esc_html_e( 'Update your script tags', 'cookiebot' ); ?></h2>
1611 <p>
1612 <?php
1613 esc_html_e(
1614 '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.',
1615 'cookiebot'
1616 );
1617 ?>
1618 </p>
1619 <code>
1620 <?php
1621 $output = <<<HTML
1622 <script type="text/plain" data-cookieconsent="statistics">
1623 (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');
1624 ga('create', 'UA-00000000-0', 'auto');
1625 ga('send', 'pageview');
1626 </script>
1627 HTML;
1628 echo nl2br( esc_html( $output ) );
1629 ?>
1630 </code>
1631 <p>
1632 <a href="https://www.youtube.com/watch?v=MeHycvV2QCQ" target="_blank" class="button">
1633 <?php
1634 esc_html_e(
1635 'Watch video demonstration',
1636 'cookiebot'
1637 );
1638 ?>
1639 </a>
1640 </p>
1641
1642 <h2><?php esc_html_e( 'Helper function to update your scripts', 'cookiebot' ); ?></h2>
1643 <p>
1644 <?php
1645 esc_html_e(
1646 'You are able to update your scripts yourself. However, Cookiebot also offers a small helper function that makes the work easier.',
1647 'cookiebot'
1648 );
1649 ?>
1650 <br/>
1651 <?php esc_html_e( 'Update your script tags this way:', 'cookiebot' ); ?>
1652 </p>
1653 <?php
1654 printf(
1655 esc_html__( '%1$s to %2$s', 'cookiebot' ),
1656 '<code>' . esc_html( '<script type="text/javascript">' ) . '</code>',
1657 '<code>' . esc_html( '<script<?php echo cookiebot_assist(\'marketing\') ?>>' ) . '</code>'
1658 );
1659 ?>
1660 </div>
1661 <?php
1662 }
1663
1664 /**
1665 * Cookiebot_WP Google Tag Manager page
1666 *
1667 * @version 3.8.1
1668 * @since 3.8.1
1669 */
1670
1671 public function GTM_page() {
1672 ?>
1673 <div class="wrap">
1674 <h1><?php esc_html_e( 'Google Tag Manager', 'cookiebot' ); ?></h1>
1675
1676 <form method="post" action="options.php"
1677 style="display: grid; grid-template-columns: 35% 65%; grid-row-gap: 20px; width: 700px; align-items: center;">
1678 <?php settings_fields( 'cookiebot-gtm' ); ?>
1679 <?php do_settings_sections( 'cookiebot-gtm' ); ?>
1680
1681 <p><?php esc_html_e( 'Enable GTM', 'cookiebot' ); ?></p>
1682 <div class="GTM_check">
1683 <input type="checkbox" name="cookiebot-gtm" id="cookiebot-gtm" value="1" <?php checked( 1, get_option( 'cookiebot-gtm' ), true ); ?>
1684 style="float: left; margin: 2px 4px 0 0">
1685 <p style="margin: 0; font-style: italic;">
1686 <?php
1687 esc_html_e(
1688 'For more details about Cookiebot and Google Tag Manager click',
1689 'cookiebot'
1690 );
1691 ?>
1692 <a target="_blank" href="https://www.cookiebot.com/en/google-tag-manager-and-gdpr-compliance-with-cookiebot/"
1693 style="margin: 0; font-style: italic;">&nbsp;<?php esc_html_e( 'here', 'cookiebot' ); ?></a></p>
1694 </div>
1695
1696 <p><?php esc_html_e( 'GTM ID', 'cookiebot' ); ?></p>
1697 <input type="text" name="cookiebot-gtm-id" id="cookiebot-gtm-id" value="<?php echo esc_attr( get_option( 'cookiebot-gtm-id' ) ); ?>"
1698 style="height: 30px;">
1699
1700 <p><?php esc_html_e( 'DataLayer name', 'cookiebot' ); ?></p>
1701 <div>
1702 <input type="text" name="cookiebot-data-layer" id="data_layer" placeholder="dataLayer"
1703 value="<?php echo esc_attr( get_option( 'cookiebot-data-layer' ) ); ?>" style="height: 30px;">
1704 <p style="margin: 0;"><?php esc_html_e( 'Optional, only change if necessary', 'cookiebot' ); ?></p>
1705 </div>
1706
1707 <p><?php esc_html_e( 'Google Consent Mode', 'cookiebot' ); ?></p>
1708 <div class="GTM_check">
1709 <input type="checkbox" name="cookiebot-gcm" id="gcm" value="1" <?php checked( 1, get_option( 'cookiebot-gcm' ), true ); ?>
1710 style="float: left; margin: 2px 4px 0 0">
1711 <p style="margin: 0; font-style: italic;">
1712 <?php
1713 esc_html_e(
1714 'For more details about Cookiebot and Google Consent Mode click',
1715 'cookiebot'
1716 );
1717 ?>
1718 <a target="_blank"
1719 href="https://support.cookiebot.com/hc/en-us/articles/360016047000-Cookiebot-and-Google-Consent-Mode"
1720 style="margin: 0; font-style: italic;">&nbsp;<?php esc_html_e( 'here', 'cookiebot' ); ?></a></p>
1721 </div>
1722 <input type="submit" value="Save" name="gtm_save"
1723 style="background-color: rgb(0, 124, 186); color: white; padding: 5px 10px; border: none; border-radius: 5px; justify-self: start;">
1724 </form>
1725 </div>
1726 <?php
1727 }
1728
1729 /**
1730 * Cookiebot_WP Cookiebot IAB page
1731 *
1732 * @version 2.0.0
1733 * @since 2.0.0
1734 */
1735 public function iab_page() {
1736 ?>
1737 <div class="wrap">
1738 <h1><?php esc_html_e( 'IAB', 'cookiebot' ); ?></h1>
1739
1740 <p>
1741 <?php
1742 echo sprintf(
1743 esc_html__(
1744 'For more details about Cookiebot\'s IAB integration, see %1$sarticle about cookiebot and the IAB consent framework%2$s',
1745 'cookiebot'
1746 ),
1747 '<a href="https://support.cookiebot.com/hc/en-us/articles/360007652694-Cookiebot-and-the-IAB-Consent-Framework" target="_blank">',
1748 '</a>'
1749 );
1750 ?>
1751 </p>
1752
1753 <form method="post" action="options.php">
1754 <?php settings_fields( 'cookiebot-iab' ); ?>
1755 <?php do_settings_sections( 'cookiebot-iab' ); ?>
1756
1757 <label><?php esc_html_e( 'Enable IAB integration', 'cookiebot' ); ?></label>
1758 <input type="checkbox" name="cookiebot-iab" value="1" <?php checked( 1, get_option( 'cookiebot-iab' ), true ); ?>>
1759
1760 <?php submit_button(); ?>
1761 </form>
1762 </div>
1763 <?php
1764 }
1765
1766 /**
1767 * Cookiebot_WP Cookiebot legislations page
1768 *
1769 * @version 3.6.6
1770 * @since 3.6.6
1771 */
1772 public function legislations_page() {
1773 ?>
1774 <div class="wrap">
1775 <h1><?php esc_html_e( 'Legislations', 'cookiebot' ); ?></h1>
1776
1777 <p>
1778 <?php
1779 echo sprintf(
1780 esc_html__(
1781 'For more details about Cookiebot\'s CCPA Legislation integration, see %1$sarticle about cookiebot and the CCPA compliance%2$s',
1782 'cookiebot'
1783 ),
1784 '<a href="https://support.cookiebot.com/hc/en-us/articles/360010932419-Use-multiple-banners-on-the-same-website-support-both-CCPA-GDPR-compliance-" target="_blank">',
1785 '</a>'
1786 );
1787 ?>
1788 </p>
1789
1790 <form method="post" action="options.php">
1791 <?php settings_fields( 'cookiebot-legislations' ); ?>
1792 <?php do_settings_sections( 'cookiebot-legislations' ); ?>
1793
1794
1795 <table class="form-table">
1796 <tbody>
1797 <tr valign="top">
1798 <th scope="row"><label><?php esc_html_e( 'Enable CCPA configuration for visitors from California', 'cookiebot' ); ?></label></th>
1799 <td>
1800 <input type="checkbox" name="cookiebot-ccpa" value="1" <?php checked( 1, get_option( 'cookiebot-ccpa' ), true ); ?>>
1801 </td>
1802 </tr>
1803 <tr>
1804 <th valign="top"><label><?php esc_html_e( 'Domain Group ID', 'cookiebot' ); ?></label></th>
1805 <td>
1806 <input type="text" style="width: 300px;" name="cookiebot-ccpa-domain-group-id"
1807 value="<?php echo esc_attr( get_option( 'cookiebot-ccpa-domain-group-id' ) ); ?>">
1808 </td>
1809 </tr>
1810 </tbody>
1811 </table>
1812
1813 <?php submit_button(); ?>
1814 </form>
1815 </div>
1816 <?php
1817 }
1818
1819 /**
1820 * Cookiebot_WP Debug Page
1821 *
1822 * @version 3.9.
1823 * @since 3.6.0
1824 */
1825
1826 public function debug_page() {
1827 global $wpdb;
1828
1829 include_once ABSPATH . 'wp-admin/includes/plugin.php';
1830 $plugins = get_plugins();
1831 $active_plugins = get_option( 'active_plugins' );
1832
1833 //$foo = new cookiebot_addons\lib\Settings_Service;
1834 //$addons = $foo->get_active_addons();
1835
1836 $debugStr = '';
1837 $debugStr .= '##### Debug Information for ' . get_site_url() . ' generated at ' . date( 'c' ) . " #####\n\n";
1838 $debugStr .= 'WordPress Version: ' . get_bloginfo( 'version' ) . "\n";
1839 $debugStr .= 'WordPress Language: ' . get_bloginfo( 'language' ) . "\n";
1840 $debugStr .= 'PHP Version: ' . phpversion() . "\n";
1841 $debugStr .= 'MySQL Version: ' . $wpdb->db_version() . "\n";
1842 $debugStr .= "\n--- Cookiebot Information ---\n";
1843 $debugStr .= 'Plugin Version: ' . $this->version . "\n";
1844 $debugStr .= 'Cookiebot ID: ' . $this->get_cbid() . "\n";
1845 $debugStr .= 'Blocking mode: ' . get_option( 'cookiebot-cookie-blocking-mode' ) . "\n";
1846 $debugStr .= 'Language: ' . get_option( 'cookiebot-language' ) . "\n";
1847 $debugStr .= 'IAB: ' . ( get_option( 'cookiebot-iab' ) == '1' ? 'Enabled' : 'Not enabled' ) . "\n";
1848 $debugStr .= 'CCPA banner for visitors from California: ' . ( get_option( 'cookiebot-ccpa' ) == '1' ? 'Enabled' : 'Not enabled' ) . "\n";
1849 $debugStr .= 'CCPA domain group id: ' . get_option( 'cookiebot-ccpa-domain-group-id' ) . "\n";
1850 $debugStr .= 'Add async/defer to banner tag: ' . ( get_option( 'cookiebot-script-tag-uc-attribute' ) != '' ? get_option( 'cookiebot-script-tag-uc-attribute' ) : 'None' ) . "\n";
1851 $debugStr .= 'Add async/defer to declaration tag: ' . ( get_option( 'cookiebot-script-tag-cd-attribute' ) != '' ? get_option( 'cookiebot-script-tag-cd-attribute' ) : 'None' ) . "\n";
1852 $debugStr .= 'Auto update: ' . ( get_option( 'cookiebot-autoupdate' ) == '1' ? 'Enabled' : 'Not enabled' ) . "\n";
1853 $debugStr .= 'Hide Cookie Popup: ' . ( get_option( 'cookiebot-nooutput' ) == '1' ? 'Yes' : 'No' ) . "\n";
1854 $debugStr .= 'Disable Cookiebot in WP Admin: ' . ( get_option( 'cookiebot-nooutput-admin' ) == '1' ? 'Yes' : 'No' ) . "\n";
1855 $debugStr .= 'Enable Cookiebot on front end while logged in: ' . ( get_option( 'cookiebot-output-logged-in' ) == '1' ? 'Yes' : 'No' ) . "\n";
1856 $debugStr .= 'Banner tag: ' . $this->add_js( false ) . "\n";
1857 $debugStr .= 'Declaration tag: ' . $this->show_declaration() . "\n";
1858
1859 if ( get_option( 'cookiebot-gtm' ) != false ) {
1860 $debugStr .= 'GTM tag: ' . $this->add_GTM( false ) . "\n";
1861 }
1862
1863 if ( get_option( 'cookiebot-gcm' ) != false ) {
1864 $debugStr .= 'GCM tag: ' . $this->add_GCM( false ) . "\n";
1865 }
1866
1867 if ( $this->is_wp_consent_api_active() ) {
1868 $debugStr .= "\n--- WP Consent Level API Mapping ---\n";
1869 $debugStr .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous' . "\n";
1870 $m = $this->get_wp_consent_api_mapping();
1871 foreach ( $m as $k => $v ) {
1872 $cb = array();
1873
1874 $debugStr .= strtoupper( str_replace( ';', ', ', $k ) ) . ' => ';
1875
1876 $debugStr .= 'F=1, ';
1877 $debugStr .= 'P=' . $v['preferences'] . ', ';
1878 $debugStr .= 'M=' . $v['marketing'] . ', ';
1879 $debugStr .= 'S=' . $v['statistics'] . ', ';
1880 $debugStr .= 'SA=' . $v['statistics-anonymous'] . "\n";
1881
1882 }
1883 }
1884
1885 if ( class_exists( 'cookiebot_addons\Cookiebot_Addons' ) ) {
1886 $ca = new cookiebot_addons\Cookiebot_Addons();
1887 $settingservice = $ca->container->get( 'Settings_Service_Interface' );
1888 $addons = $settingservice->get_active_addons();
1889 $debugStr .= "\n--- Activated Cookiebot Addons ---\n";
1890 foreach ( $addons as $addon ) {
1891 $debugStr .= $addon->get_addon_name() . ' (' . implode( ', ', $addon->get_cookie_types() ) . ")\n";
1892 }
1893 }
1894
1895 $debugStr .= "\n--- Activated Plugins ---\n";
1896 foreach ( $active_plugins as $p ) {
1897 if ( $p != 'cookiebot/cookiebot.php' ) {
1898 $debugStr .= $plugins[ $p ]['Name'] . ' (Version: ' . $plugins[ $p ]['Version'] . ")\n";
1899 }
1900 }
1901
1902 $debugStr .= "\n##### Debug Information END #####";
1903
1904 ?>
1905 <div class="wrap">
1906 <h1><?php esc_html_e( 'Debug information', 'cookiebot' ); ?></h1>
1907 <p>
1908 <?php
1909 esc_html_e(
1910 'The information below is for debugging purpose. If you have any issues with your Cookiebot integration, the information below is usefull for a supporter to help you the best way.',
1911 'cookiebot'
1912 );
1913 ?>
1914 </p>
1915 <p>
1916 <button class="button button-primary" onclick="copyDebugInfo();">
1917 <?php
1918 esc_html_e(
1919 'Copy debug information to clipboard',
1920 'cookiebot'
1921 );
1922 ?>
1923 </button>
1924 </p>
1925 <textarea
1926 cols="100"
1927 rows="40"
1928 style="width:800px;max-width:100%;"
1929 id="cookiebot-debug-info"
1930 readonly><?php echo esc_html( $debugStr ); ?></textarea>
1931 <script>
1932 function copyDebugInfo() {
1933 var t = document.getElementById( "cookiebot-debug-info" );
1934 t.select();
1935 t.setSelectionRange( 0, 99999 );
1936 document.execCommand( "copy" );
1937 }
1938 </script>
1939 </div>
1940 <?php
1941 }
1942
1943 /**
1944 * Cookiebot_WP Add Cookiebot JS to <head>
1945 *
1946 * @version 3.9.0
1947 * @since 1.0.0
1948 */
1949 public function add_js( $print_tag = true ) {
1950 $cbid = $this->get_cbid();
1951 if ( ! empty( $cbid ) && ! defined( 'COOKIEBOT_DISABLE_ON_PAGE' ) ) {
1952 if ( is_multisite() && get_site_option( 'cookiebot-nooutput', false ) ) {
1953 return; //Is multisite - and disabled output is checked as network setting
1954 }
1955
1956 if ( get_option( 'cookiebot-nooutput', false ) ) {
1957 return; //Do not show JS - output disabled
1958 }
1959
1960 if ( $this->get_cookie_blocking_mode() == 'auto' && $this->can_current_user_edit_theme() && $print_tag !== false && get_site_option( 'cookiebot-output-logged-in' ) == false ) {
1961 return;
1962 }
1963
1964 $lang = $this->get_language();
1965
1966 if ( ! is_multisite() || get_site_option( 'cookiebot-script-tag-uc-attribute', 'custom' ) == 'custom' ) {
1967 $tagAttr = get_option( 'cookiebot-script-tag-uc-attribute', 'async' );
1968 } else {
1969 $tagAttr = get_site_option( 'cookiebot-script-tag-uc-attribute' );
1970 }
1971
1972 if ( $print_tag === false ) {
1973 ob_start();
1974 }
1975 ?>
1976 <script type="text/javascript"
1977 id="Cookiebot"
1978 src="https://consent.cookiebot.com/uc.js"
1979 data-cbid="<?php echo esc_attr( $cbid ); ?>"
1980 <?php if ( (bool) get_option( 'cookiebot-iab' ) !== false ) : ?>
1981 data-framework="IAB"
1982 <?php endif; ?>
1983 <?php if ( (bool) get_option( 'cookiebot-ccpa' ) !== false ) : ?>
1984 data-georegions="{'region':'US-06','cbid':'<?php echo esc_attr( get_option( 'cookiebot-ccpa-domain-group-id' ) ); ?>'}"
1985 <?php endif; ?>
1986 <?php if ( (bool) get_option( 'cookiebot-gtm' ) !== false ) : ?>
1987 <?php if ( empty( get_option( 'cookiebot-data-layer' ) ) ) : ?>
1988 data-layer-name="dataLayer"
1989 <?php else : ?>
1990 data-layer-name="<?php echo esc_attr( get_option( 'cookiebot-data-layer' ) ); ?>"
1991 <?php endif; ?>
1992 <?php endif; ?>
1993 <?php if ( ! empty( $lang ) ) : ?>
1994 data-culture="<?php echo esc_attr( strtoupper( $lang ) ); ?>"
1995 <?php endif; ?>
1996 <?php if ( $this->get_cookie_blocking_mode() === 'auto' ) : ?>
1997 data-blockingmode="auto"
1998 <?php else : ?>
1999 <?php echo esc_attr( $tagAttr ); ?>
2000 <?php endif; ?>
2001 ></script>
2002 <?php
2003 if ( $print_tag === false ) {
2004 return ob_get_clean();
2005 }
2006 }
2007 }
2008
2009 /**
2010 * Cookiebot_WP Add Google Tag Manager JS to <head>
2011 *
2012 * @version 3.8.1
2013 * @since 3.8.1
2014 */
2015
2016 public function add_GTM( $print_tag = true ) {
2017 if ( (bool) get_option( 'cookiebot-gtm' ) !== false ) {
2018 if ( empty( get_option( 'cookiebot-data-layer' ) ) ) {
2019 $data_layer = 'dataLayer';
2020 } else {
2021 $data_layer = get_option( 'cookiebot-data-layer' );
2022 }
2023
2024 if ( $print_tag === false ) {
2025 ob_start();
2026 }
2027 ?>
2028 <script>
2029 <?php if ( get_option( 'cookiebot-iab' ) ) : ?>
2030 window ["gtag_enable_tcf_support"] = true;
2031 <?php endif; ?>
2032 (function (w, d, s, l, i) {
2033 w[l] = w[l] || []; w[l].push({'gtm.start':new Date().getTime(), event: 'gtm.js'});
2034 var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
2035 j.async = true; j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
2036 f.parentNode.insertBefore(j, f);})
2037 (window, document, 'script', '<?php echo esc_js( $data_layer ); ?>', '<?php echo esc_js( get_option( 'cookiebot-gtm-id' ) ); ?>');
2038 </script>
2039 <?php
2040 if ( $print_tag === false ) {
2041 return ob_get_clean();
2042 }
2043 }
2044 }
2045
2046 /**
2047 * Cookiebot_WP Add Google Consent Mode JS to <head>
2048 *
2049 * @version 3.8.1
2050 * @since 3.8.1
2051 */
2052
2053 public function add_GCM( $print_tag = true ) {
2054 if ( (bool) get_option( 'cookiebot-gcm' ) !== false ) {
2055 if ( empty( get_option( 'cookiebot-data-layer' ) ) ) {
2056 $data_layer = 'dataLayer';
2057 } else {
2058 $data_layer = get_option( 'cookiebot-data-layer' );
2059 }
2060
2061 if ( $print_tag === false ) {
2062 ob_start();
2063 }
2064 ?>
2065 <script data-cookieconsent="ignore">
2066 (function(w,d,l){w[l]=w[l]||[];function gtag(){w[l].push(arguments)}
2067 gtag("consent","default",{ad_storage:d,analytics_storage:d,wait_for_update:500,});
2068 gtag("set", "ads_data_redaction", true);})(window,"denied","<?php echo esc_js( $data_layer ); ?>");
2069 </script>
2070 <?php
2071 if ( $print_tag === false ) {
2072 return ob_get_clean();
2073 }
2074 }
2075 }
2076
2077 /**
2078 * Returns true if an user is logged in and has an edit_themes capability
2079 *
2080 * @return bool
2081 *
2082 * @since 3.3.1
2083 * @version 3.4.1
2084 */
2085 public function can_current_user_edit_theme() {
2086 if ( is_user_logged_in() ) {
2087 if ( current_user_can( 'edit_themes' ) ) {
2088 return true;
2089 }
2090
2091 if ( current_user_can( 'edit_pages' ) ) {
2092 return true;
2093 }
2094
2095 if ( current_user_can( 'edit_posts' ) ) {
2096 return true;
2097 }
2098 }
2099
2100 return false;
2101 }
2102
2103 /**
2104 * Cookiebot_WP Output declation shortcode [cookie_declaration]
2105 * Support attribute lang="LANGUAGE_CODE". Eg. lang="en".
2106 *
2107 * @version 2.2.0
2108 * @since 1.0.0
2109 */
2110 public function show_declaration( $atts = array() ) {
2111 $cbid = $this->get_cbid();
2112 $lang = '';
2113 if ( ! empty( $cbid ) ) {
2114
2115 $atts = shortcode_atts(
2116 array(
2117 'lang' => $this->get_language(),
2118 ),
2119 $atts,
2120 'cookie_declaration'
2121 );
2122
2123 if ( ! empty( $atts['lang'] ) ) {
2124 $lang = ' data-culture="' . strtoupper( $atts['lang'] ) . '"'; //Use data-culture to define language
2125 }
2126
2127 if ( ! is_multisite() || get_site_option( 'cookiebot-script-tag-cd-attribute', 'custom' ) == 'custom' ) {
2128 $tagAttr = get_option( 'cookiebot-script-tag-cd-attribute', 'async' );
2129 } else {
2130 $tagAttr = get_site_option( 'cookiebot-script-tag-cd-attribute' );
2131 }
2132
2133 return '<script id="CookieDeclaration" src="https://consent.cookiebot.com/' . $cbid . '/cd.js"' . $lang . ' type="text/javascript" ' . $tagAttr . '></script>';
2134 } else {
2135 return esc_html__( 'Please add your Cookiebot ID to show Cookie Declarations', 'cookiebot' );
2136 }
2137 }
2138
2139 /**
2140 * Cookiebot_WP Get cookiebot cbid
2141 *
2142 * @version 2.2.0
2143 * @since 1.0.0
2144 */
2145 public static function get_cbid() {
2146 $cbid = get_option( 'cookiebot-cbid' );
2147 if ( is_multisite() && ( $network_cbid = get_site_option( 'cookiebot-cbid' ) ) ) {
2148 if ( empty( $cbid ) ) {
2149 return $network_cbid;
2150 }
2151 }
2152
2153 return $cbid;
2154 }
2155
2156 /**
2157 * Cookiebot_WP Get cookie blocking mode (auto | manual)
2158 *
2159 * @version 2.2.0
2160 * @since 1.0.0
2161 */
2162 public static function get_cookie_blocking_mode() {
2163 $cbm = get_option( 'cookiebot-cookie-blocking-mode' );
2164 if ( is_multisite() && ( $network_cbm = get_site_option( 'cookiebot-cookie-blocking-mode' ) ) ) {
2165 if ( empty( $cbm ) ) {
2166 return $network_cbm;
2167 }
2168 }
2169 if ( empty( $cbm ) ) {
2170 $cbm = 'manual';
2171 }
2172
2173 return $cbm;
2174 }
2175
2176
2177 /**
2178 * Cookiebot_WP Check if Cookiebot is active in admin
2179 *
2180 * @version 3.1.0
2181 * @since 3.1.0
2182 */
2183 public static function cookiebot_disabled_in_admin() {
2184 if ( is_multisite() && get_site_option( 'cookiebot-nooutput-admin', false ) ) {
2185 return true;
2186 } elseif ( get_option( 'cookiebot-nooutput-admin', false ) ) {
2187 return true;
2188 }
2189
2190 return false;
2191 }
2192
2193 /**
2194 * Cookiebot_WP Get the language code for Cookiebot
2195 *
2196 * @version 1.4.0
2197 * @since 1.4.0
2198 */
2199 public function get_language( $onlyFromSetting = false ) {
2200 // Get language set in setting page - if empty use WP language info
2201 $lang = get_option( 'cookiebot-language' );
2202 if ( ! empty( $lang ) ) {
2203 if ( $lang != '_wp' ) {
2204 return $lang;
2205 }
2206 }
2207
2208 if ( $onlyFromSetting ) {
2209 return $lang; //We want only to get if already set
2210 }
2211
2212 //Language not set - use WP language
2213 if ( $lang == '_wp' ) {
2214 $lang = get_bloginfo( 'language' ); //Gets language in en-US format
2215 if ( ! empty( $lang ) ) {
2216 list( $lang ) = explode( '-', $lang ); //Changes format from eg. en-US to en.
2217 }
2218 }
2219
2220 return $lang;
2221 }
2222
2223 /**
2224 * Cookiebot_WP Adding Cookiebot domain(s) to exclude list for WP Rocket minification.
2225 *
2226 * @version 1.6.1
2227 * @since 1.6.1
2228 */
2229 public function wp_rocket_exclude_external_js( $external_js_hosts ) {
2230 $external_js_hosts[] = 'consent.cookiebot.com'; // Add cookiebot domains
2231 $external_js_hosts[] = 'consentcdn.cookiebot.com';
2232
2233 return $external_js_hosts;
2234 }
2235
2236 /**
2237 * Cookiebot_WP Adding Cookiebot domain(s) to exclude list for SGO minification.
2238 *
2239 * @version 3.6.5
2240 * @since 3.6.5
2241 */
2242 public function sgo_exclude_external_js( $exclude_list ) {
2243 //Uses same format as WP Rocket - for now we just use WP Rocket function
2244 return wp_rocket_exclude_external_js( $exclude_list );
2245 }
2246
2247
2248 /**
2249 * Cookiebot_WP Check if WP Cookie Consent API is active
2250 *
2251 * @version 3.5.0
2252 * @since 3.5.0
2253 */
2254 public function is_wp_consent_api_active() {
2255 if ( class_exists( 'WP_CONSENT_API' ) ) {
2256 return true;
2257 }
2258
2259 return false;
2260 }
2261
2262 /**
2263 * Cookiebot_WP Default consent level mappings
2264 *
2265 * @version 3.5.0
2266 * @since 3.5.0
2267 */
2268 public function get_default_wp_consent_api_mapping() {
2269 return array(
2270 'n=1;p=1;s=1;m=1' =>
2271 array(
2272 'preferences' => 1,
2273 'statistics' => 1,
2274 'statistics-anonymous' => 0,
2275 'marketing' => 1,
2276 ),
2277 'n=1;p=1;s=1;m=0' =>
2278 array(
2279 'preferences' => 1,
2280 'statistics' => 1,
2281 'statistics-anonymous' => 1,
2282 'marketing' => 0,
2283 ),
2284 'n=1;p=1;s=0;m=1' =>
2285 array(
2286 'preferences' => 1,
2287 'statistics' => 0,
2288 'statistics-anonymous' => 0,
2289 'marketing' => 1,
2290 ),
2291 'n=1;p=1;s=0;m=0' =>
2292 array(
2293 'preferences' => 1,
2294 'statistics' => 0,
2295 'statistics-anonymous' => 0,
2296 'marketing' => 0,
2297 ),
2298 'n=1;p=0;s=1;m=1' =>
2299 array(
2300 'preferences' => 0,
2301 'statistics' => 1,
2302 'statistics-anonymous' => 0,
2303 'marketing' => 1,
2304 ),
2305 'n=1;p=0;s=1;m=0' =>
2306 array(
2307 'preferences' => 0,
2308 'statistics' => 1,
2309 'statistics-anonymous' => 0,
2310 'marketing' => 0,
2311 ),
2312 'n=1;p=0;s=0;m=1' =>
2313 array(
2314 'preferences' => 0,
2315 'statistics' => 0,
2316 'statistics-anonymous' => 0,
2317 'marketing' => 1,
2318 ),
2319 'n=1;p=0;s=0;m=0' =>
2320 array(
2321 'preferences' => 0,
2322 'statistics' => 0,
2323 'statistics-anonymous' => 0,
2324 'marketing' => 0,
2325 ),
2326 );
2327
2328 }
2329
2330 /**
2331 * Cookiebot_WP Get the mapping between Consent Level API and Cookiebot
2332 * Returns array where key is the consent level api category and value
2333 * is the mapped Cookiebot category.
2334 *
2335 * @version 3.5.0
2336 * @since 3.5.0
2337 */
2338 public function get_wp_consent_api_mapping() {
2339 $mDefault = $this->get_default_wp_consent_api_mapping();
2340 $mapping = get_option( 'cookiebot-consent-mapping', $mDefault );
2341
2342 $mapping = ( '' === $mapping ) ? $mDefault : $mapping;
2343
2344 foreach ( $mDefault as $k => $v ) {
2345 if ( ! isset( $mapping[ $k ] ) ) {
2346 $mapping[ $k ] = $v;
2347 } else {
2348 foreach ( $v as $vck => $vcv ) {
2349 if ( ! isset( $mapping[ $k ][ $vck ] ) ) {
2350 $mapping[ $k ][ $vck ] = $vcv;
2351 }
2352 }
2353 }
2354 }
2355
2356 return $mapping;
2357 }
2358
2359 /**
2360 * Cookiebot_WP Enqueue JS for integration with WP Consent Level API
2361 *
2362 * @version 3.5.0
2363 * @since 3.5.0
2364 */
2365 public function cookiebot_enqueue_consent_api_scripts() {
2366 wp_register_script(
2367 'cookiebot-wp-consent-level-api-integration',
2368 plugins_url( 'cookiebot/js/cookiebot-wp-consent-level-api-integration.js', 'cookiebot' )
2369 );
2370 wp_enqueue_script( 'cookiebot-wp-consent-level-api-integration' );
2371 wp_localize_script( 'cookiebot-wp-consent-level-api-integration', 'cookiebot_category_mapping', $this->get_wp_consent_api_mapping() );
2372 }
2373
2374
2375 /**
2376 * Display admin notice for recommending cookiebot
2377 *
2378 * @version 2.0.5
2379 * @since 2.0.5
2380 */
2381 public function cookiebot_admin_notices() {
2382 if ( ! $this->cookiebot_valid_admin_recommendation() ) {
2383 return false;
2384 }
2385 $two_week_review_ignore = add_query_arg( array( 'cookiebot_admin_notice' => 'hide' ) );
2386 $two_week_review_temp = add_query_arg( array( 'cookiebot_admin_notice' => 'two_week' ) );
2387
2388 ?>
2389 <div class="update-nag cookiebot-admin-notice">
2390 <div class="cookiebot-notice-logo"></div>
2391 <p class="cookiebot-notice-title"><?php echo esc_html__( 'Leave A Review?', 'cookiebot' ); ?></p>
2392 <p class="cookiebot-notice-body">
2393 <?php
2394 echo esc_html__(
2395 'We hope you enjoy using WordPress Cookiebot! Would you consider leaving us a review on WordPress.org?',
2396 'cookiebot'
2397 );
2398 ?>
2399 </p>
2400 <ul class="cookiebot-notice-body wd-blue">
2401 <li>
2402 <span class="dashicons dashicons-external"></span>
2403 <a href="https://wordpress.org/support/plugin/cookiebot/reviews?filter=5&rate=5#new-post" target="_blank">
2404 <?php
2405 echo esc_html__(
2406 'Sure! I\'d love to!',
2407 'cookiebot'
2408 );
2409 ?>
2410 </a>
2411 </li>
2412 <li>
2413 <span class="dashicons dashicons-smiley"></span>
2414 <a href="<?php echo esc_url( $two_week_review_ignore ); ?>">
2415 <?php
2416 echo esc_html__(
2417 'I\'ve already left a review',
2418 'cookiebot'
2419 );
2420 ?>
2421 </a>
2422 </li>
2423 <li>
2424 <span class="dashicons dashicons-calendar-alt"></span>
2425 <a href="<?php echo esc_url( $two_week_review_temp ); ?>">
2426 <?php
2427 echo esc_html__(
2428 'Maybe Later',
2429 'cookiebot'
2430 );
2431 ?>
2432 </a>
2433 </li>
2434 <li>
2435 <span class="dashicons dashicons-dismiss"></span>
2436 <a href="<?php echo esc_url( $two_week_review_ignore ); ?>">
2437 <?php
2438 echo esc_html__(
2439 'Never show again',
2440 'cookiebot'
2441 );
2442 ?>
2443 </a>
2444 </li>
2445 </ul>
2446 <a href="<?php esc_url( $two_week_review_temp ); ?>" class="dashicons dashicons-dismiss"></a>
2447 </div>
2448 <?php
2449
2450 wp_enqueue_style( 'cookiebot-admin-notices', plugins_url( 'css/notice.css', __FILE__ ), array(), '2.0.4' );
2451 }
2452
2453
2454 /**
2455 * Validate if the last user action is valid for plugin recommendation
2456 *
2457 * @return bool
2458 *
2459 * @version 2.0.5
2460 * @since 2.0.5
2461 */
2462 public function cookiebot_valid_admin_recommendation() {
2463 //Default - the recommendation is allowed to be visible
2464 $return = true;
2465
2466 $option = get_option( 'cookiebot_notice_recommend' );
2467
2468 if ( $option != false ) {
2469 //Never show again is clicked
2470 if ( $option == 'hide' ) {
2471 $return = false;
2472 } elseif ( is_numeric( $option ) && strtotime( 'now' ) < $option ) {
2473 //Show me after 2 weeks is clicked and the time is not valid yet
2474 $return = false;
2475 }
2476 }
2477
2478 return $return;
2479 }
2480
2481 /**
2482 * Save the user action on cookiebot recommendation link
2483 *
2484 * @version 2.0.5
2485 * @since 2.0.5
2486 */
2487 public function save_notice_link() {
2488 if ( isset( $_GET['cookiebot_admin_notice'] ) ) {
2489 if ( $_GET['cookiebot_admin_notice'] === 'hide' ) {
2490 update_option( 'cookiebot_notice_recommend', 'hide' );
2491 } else {
2492 update_option( 'cookiebot_notice_recommend', strtotime( '+2 weeks' ) );
2493 }
2494 }
2495 }
2496
2497
2498 /**
2499 * Cookiebot_WP Fix plugin conflicts related to Cookiebot
2500 *
2501 * @version 3.2.0
2502 * @since 3.3.0
2503 */
2504 public function cookiebot_fix_plugin_conflicts() {
2505 //Fix for Divi Page Builder
2506 //Disabled - using another method now (can_current_user_edit_theme())
2507 //add_action( 'wp', array( $this, '_cookiebot_plugin_conflict_divi' ), 100 );
2508
2509 //Fix for Elementor and WPBakery Page Builder Builder
2510 //Disabled - using another method now (can_current_user_edit_theme())
2511 //add_filter( 'script_loader_tag', array( $this, '_cookiebot_plugin_conflict_scripttags' ), 10, 2 );
2512 }
2513
2514 /**
2515 * Cookiebot_WP Fix Divi builder conflict when blocking mode is in auto.
2516 *
2517 * @version 3.2.0
2518 * @since 3.2.0
2519 */
2520 public function _cookiebot_plugin_conflict_divi() {
2521 if ( defined( 'ET_FB_ENABLED' ) ) {
2522 if ( ET_FB_ENABLED &&
2523 $this->cookiebot_disabled_in_admin() &&
2524 $this->get_cookie_blocking_mode() == 'auto' ) {
2525
2526 define( 'COOKIEBOT_DISABLE_ON_PAGE', true ); //Disable Cookiebot on the current page
2527
2528 }
2529 }
2530 }
2531
2532 /**
2533 * Cookiebot_WP Fix plugin conflicts with page builders - whitelist JS files in automode
2534 *
2535 * @version 3.2.0
2536 * @since 3.3.0
2537 */
2538 public function _cookiebot_plugin_conflict_scripttags( $tag, $handle ) {
2539
2540 //Check if Elementor Page Builder active
2541 if ( defined( 'ELEMENTOR_VERSION' ) ) {
2542 if ( in_array(
2543 $handle,
2544 array(
2545 'jquery-core',
2546 'elementor-frontend-modules',
2547 'elementor-frontend',
2548 'wp-tinymce',
2549 'underscore',
2550 'backbone',
2551 'backbone-marionette',
2552 'backbone-radio',
2553 'elementor-common-modules',
2554 'elementor-dialog',
2555 'elementor-common',
2556 )
2557 ) ) {
2558 $tag = str_replace( '<script ', '<script data-cookieconsent="ignore" ', $tag );
2559 }
2560 }
2561
2562 //Check if WPBakery Page Builder active
2563 if ( defined( 'WPB_VC_VERSION' ) ) {
2564 if ( in_array(
2565 $handle,
2566 array(
2567 'jquery-core',
2568 'jquery-ui-core',
2569 'jquery-ui-sortable',
2570 'jquery-ui-mouse',
2571 'jquery-ui-widget',
2572 'vc_editors-templates-preview-js',
2573 'vc-frontend-editor-min-js',
2574 'vc_inline_iframe_js',
2575 'wpb_composer_front_js',
2576 )
2577 ) ) {
2578 $tag = str_replace( '<script ', '<script data-cookieconsent="ignore" ', $tag );
2579 }
2580 }
2581
2582 return $tag;
2583 }
2584
2585 }
2586 endif;
2587
2588
2589 /**
2590 * Helper function to manipulate script tags
2591 *
2592 * @return string
2593 * @since 1.0
2594 * @version 1.6
2595 */
2596 function cookiebot_assist( $type = 'statistics' ) {
2597 //change to array
2598 if ( ! is_array( $type ) ) {
2599 $type = array( $type );
2600 }
2601
2602 foreach ( $type as $tk => $tv ) {
2603 if ( ! in_array( $tv, array( 'marketing', 'statistics', 'preferences' ) ) ) {
2604 unset( $type[ $tk ] );
2605 }
2606 }
2607 if ( sizeof( $type ) > 0 ) {
2608 return ' type="text/plain" data-cookieconsent="' . implode( ',', $type ) . '"';
2609 }
2610
2611 return '';
2612 }
2613
2614
2615 /**
2616 * Helper function to check if cookiebot is active.
2617 * Useful for other plugins adding support for Cookiebot.
2618 *
2619 * @return string
2620 * @since 1.2
2621 * @version 2.2.2
2622 */
2623 function cookiebot_active() {
2624 $cbid = Cookiebot_WP::get_cbid();
2625 if ( ! empty( $cbid ) ) {
2626 return true;
2627 }
2628
2629 return false;
2630 }
2631
2632
2633 if ( ! function_exists( 'cookiebot' ) ) {
2634 /**
2635 * Returns the main instance of Cookiebot_WO to prevent the need to use globals.
2636 *
2637 * @return Cookiebot_WP
2638 * @since 1.0.0
2639 * @version 1.0.0
2640 */
2641 function cookiebot() {
2642 return Cookiebot_WP::instance();
2643 }
2644 }
2645
2646 cookiebot();
2647