PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.7.5
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.7.5
4.7.4 4.7.5 4.7.3 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 All 95 releases
cookiebot / src / lib / Cookiebot_Activated.php

Cookiebot_Activated.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 4.7.5, at src/lib/Cookiebot_Activated.php

111 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cybot\cookiebot\lib;
4
5 use cybot\cookiebot\addons\Cookiebot_Addons;
6 use cybot\cookiebot\admin_notices\Cookiebot_Recommendation_Notice;
7 use Exception;
8
9 class Cookiebot_Activated {
10
11
12 /**
13 * @throws Exception
14 */
15 public function run() {
16 $this->delay_notice_recommandation_when_it_is_first_activation();
17
18 $this->set_to_mode_auto_when_no_cookiebot_id_is_set();
19
20 $this->set_banner_enabled_by_default();
21
22 $this->set_addons_default_settings();
23
24 // Set a transient to indicate plugin was just activated
25 set_transient( 'cookiebot_just_activated', true, 30 );
26 }
27
28 public function __construct() {
29 // Add script to track activation on next page load
30 add_action(
31 'admin_head',
32 function() {
33 if ( get_transient( 'cookiebot_just_activated' ) ) {
34 delete_transient( 'cookiebot_just_activated' );
35 ?>
36 <script>
37 // Load Amplitude SDK
38 (function() {
39 const script = document.createElement('script');
40 script.src = 'https://cdn.eu.amplitude.com/script/3573fa11b8c5b4bcf577ec4c8e9d5cb6.js';
41 script.async = true;
42 script.onload = function() {
43 const amplitude = window.amplitude;
44 amplitude.init('3573fa11b8c5b4bcf577ec4c8e9d5cb6', {
45 serverZone: 'EU',
46 fetchRemoteConfig: true,
47 defaultTracking: false
48 });
49
50 // Track activation event
51 amplitude.track('Plugin Activated', {
52 source: 'Plugin Directory',
53 wordpress_role: '<?php echo esc_js( current_user_can( 'manage_options' ) ? 'Admin' : 'Editor' ); ?>',
54 plugin_version: '<?php echo esc_js( Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION ); ?>',
55 wp_version: '<?php echo esc_js( get_bloginfo( 'version' ) ); ?>',
56 });
57 };
58 document.head.appendChild(script);
59 })();
60 </script>
61 <?php
62 }
63 }
64 );
65 }
66
67 private function delay_notice_recommandation_when_it_is_first_activation() {
68 // Delay display of recommendation notice in 3 days if not activated earlier
69 if ( get_option( Cookiebot_Recommendation_Notice::COOKIEBOT_NOTICE_OPTION_KEY, false ) === false ) {
70 // Not set yet - this must be first activation - delay in 3 days
71 update_option( Cookiebot_Recommendation_Notice::COOKIEBOT_NOTICE_OPTION_KEY, strtotime( '+3 days' ) );
72 }
73 }
74
75 private function set_to_mode_auto_when_no_cookiebot_id_is_set() {
76 if ( Cookiebot_WP::get_cbid() === '' ) {
77 if ( is_multisite() ) {
78 update_site_option( 'cookiebot-cookie-blocking-mode', 'auto' );
79 update_site_option( 'cookiebot-nooutput-admin', true );
80 } else {
81 update_option( 'cookiebot-cookie-blocking-mode', 'auto' );
82 update_option( 'cookiebot-nooutput-admin', true );
83 }
84 }
85 }
86
87 private function set_banner_enabled_by_default() {
88 $enabled = get_option( 'cookiebot-banner-enabled', 'default' );
89 $cbid = Cookiebot_WP::get_cbid();
90
91 // Set to enabled if it's a fresh install (default)
92 if ( $enabled === 'default' ) {
93 $enabled = '1';
94 update_option( 'cookiebot-banner-enabled', $enabled );
95 }
96
97 // If banner is disabled but CBID is configured, it was disabled by hosting or plugin update. Re-enable it.
98 if ( $enabled === '0' && ! empty( $cbid ) ) {
99 update_option( 'cookiebot-banner-enabled', '1' );
100 }
101 }
102
103 /**
104 * @throws Exception
105 */
106 private function set_addons_default_settings() {
107 $cookiebot_addons = Cookiebot_Addons::instance();
108 $cookiebot_addons->cookiebot_activated();
109 }
110 }
111