buffer
1 year ago
script_loader_tag
1 year ago
traits
1 year ago
Account_Service.php
10 months ago
Consent_API_Helper.php
1 year ago
Cookie_Consent.php
1 year ago
Cookie_Consent_Interface.php
1 year ago
Cookiebot_Activated.php
10 months ago
Cookiebot_Admin_Links.php
1 year ago
Cookiebot_Automatic_Updates.php
1 year ago
Cookiebot_Deactivated.php
1 year ago
Cookiebot_Frame.php
1 year ago
Cookiebot_Javascript_Helper.php
10 months ago
Cookiebot_Review.php
1 year ago
Cookiebot_WP.php
10 months ago
Dependency_Container.php
1 year ago
Settings_Page_Tab.php
1 year ago
Settings_Service.php
1 year ago
Settings_Service_Interface.php
1 year ago
Supported_Languages.php
1 year ago
Supported_Regions.php
1 year ago
WP_Rocket_Helper.php
1 year ago
Widgets.php
1 year ago
global-deprecations.php
1 year ago
helper.php
10 months ago
Cookiebot_Activated.php
103 lines
| 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 | if ( $enabled === 'default' ) { |
| 90 | $enabled = '1'; |
| 91 | update_option( 'cookiebot-banner-enabled', $enabled ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @throws Exception |
| 97 | */ |
| 98 | private function set_addons_default_settings() { |
| 99 | $cookiebot_addons = Cookiebot_Addons::instance(); |
| 100 | $cookiebot_addons->cookiebot_activated(); |
| 101 | } |
| 102 | } |
| 103 |