PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.2.5
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.2.5
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 / src / lib / Cookiebot_WP.php
cookiebot / src / lib Last commit date
buffer 3 years ago script_loader_tag 3 years ago traits 3 years ago Consent_API_Helper.php 3 years ago Cookie_Consent.php 3 years ago Cookie_Consent_Interface.php 4 years ago Cookiebot_Activated.php 3 years ago Cookiebot_Automatic_Updates.php 3 years ago Cookiebot_Deactivated.php 4 years ago Cookiebot_Javascript_Helper.php 3 years ago Cookiebot_WP.php 3 years ago Dependency_Container.php 3 years ago Settings_Page_Tab.php 3 years ago Settings_Service.php 3 years ago Settings_Service_Interface.php 3 years ago Supported_Languages.php 4 years ago Supported_Regions.php 3 years ago WP_Rocket_Helper.php 3 years ago Widgets.php 3 years ago global-deprecations.php 3 years ago helper.php 3 years ago
Cookiebot_WP.php
242 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 cybot\cookiebot\gutenberg\Cookiebot_Gutenberg_Declaration_Block;
8 use cybot\cookiebot\settings\Menu_Settings;
9 use cybot\cookiebot\settings\Network_Menu_Settings;
10 use cybot\cookiebot\widgets\Dashboard_Widget_Cookiebot_Status;
11 use RuntimeException;
12
13 class Cookiebot_WP {
14 const COOKIEBOT_PLUGIN_VERSION = '4.2.5';
15 const COOKIEBOT_MIN_PHP_VERSION = '5.6.0';
16
17 /**
18 * @var Cookiebot_WP The single instance of the class
19 * @since 1.0.0
20 */
21 private static $instance = null;
22
23 /**
24 * Main Cookiebot_WP Instance
25 *
26 * Ensures only one instance of Cookiebot_WP is loaded or can be loaded.
27 *
28 * @return Cookiebot_WP - Main instance
29 * @throws RuntimeException
30 * @version 1.0.0
31 * @since 1.0.0
32 * @static
33 */
34 public static function instance() {
35 if ( is_null( self::$instance ) ) {
36 self::$instance = new self();
37 }
38
39 return self::$instance;
40 }
41
42 /**
43 * Cookiebot_WP Constructor.
44 *
45 * @throws RuntimeException
46 * @since 1.0.0
47 * @access public
48 * @version 2.1.4
49 */
50 public function __construct() {
51 $this->throw_exception_if_php_version_is_incompatible();
52
53 add_action( 'after_setup_theme', array( $this, 'cookiebot_init' ), 5 );
54 register_activation_hook( __FILE__, array( new Cookiebot_Activated(), 'run' ) );
55 register_deactivation_hook( __FILE__, array( new Cookiebot_Deactivated(), 'run' ) );
56 }
57
58 /**
59 * @throws RuntimeException
60 */
61 private function throw_exception_if_php_version_is_incompatible() {
62 if ( version_compare( PHP_VERSION, self::COOKIEBOT_MIN_PHP_VERSION, '<' ) ) {
63 $message = sprintf(
64 // translators: The placeholder is for the COOKIEBOT_MIN_PHP_VERSION constant
65 __( 'The Cookiebot plugin requires PHP version %s or greater.', 'cookiebot' ),
66 self::COOKIEBOT_MIN_PHP_VERSION
67 );
68 throw new RuntimeException( $message );
69 }
70 }
71
72 public static function register_session_new() {
73 if ( ! session_id() ) {
74 session_start();
75 }
76 }
77
78 public function cookiebot_init() {
79 add_action( 'init', array( $this, 'register_session_new' ) );
80
81 Cookiebot_Addons::instance();
82 load_textdomain(
83 'cookiebot',
84 CYBOT_COOKIEBOT_PLUGIN_DIR . 'langs/cookiebot-' . get_locale() . '.mo'
85 );
86 load_plugin_textdomain( 'cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs' );
87
88 if ( is_admin() ) {
89 ( new Menu_Settings() )->add_menu();
90 if ( is_multisite() && is_plugin_active_for_network( 'cookiebot/cookiebot.php' ) ) {
91 ( new Network_Menu_Settings() )->add_menu();
92 }
93 ( new Dashboard_Widget_Cookiebot_Status() )->register_hooks();
94 ( new Cookiebot_Recommendation_Notice() )->register_hooks();
95 }
96
97 ( new Consent_API_Helper() )->register_hooks();
98 ( new Cookiebot_Javascript_Helper() )->register_hooks();
99 ( new Cookiebot_Automatic_Updates() )->register_hooks();
100 ( new Widgets() )->register_hooks();
101 ( new Cookiebot_Gutenberg_Declaration_Block() )->register_hooks();
102 ( new WP_Rocket_Helper() )->register_hooks();
103
104 $this->set_default_options();
105 $this->delay_notice_recommendation_on_first_activation();
106 add_filter( 'plugin_action_links_cookiebot/cookiebot.php', array( $this, 'set_settings_action_link' ) );
107 }
108
109 /**
110 * Returns true if an user is logged in and has an edit_themes capability
111 *
112 * @return bool
113 *
114 * @since 3.3.1
115 * @version 3.4.1
116 */
117 public static function can_current_user_edit_theme() {
118 if ( is_user_logged_in() ) {
119 if ( current_user_can( 'edit_themes' ) ) {
120 return true;
121 }
122
123 if ( current_user_can( 'edit_pages' ) ) {
124 return true;
125 }
126
127 if ( current_user_can( 'edit_posts' ) ) {
128 return true;
129 }
130 }
131
132 return false;
133 }
134
135 /**
136 * @return string
137 */
138 public static function get_cbid() {
139 $network_setting = (string) get_site_option( 'cookiebot-cbid', '' );
140 $setting = (string) get_option( 'cookiebot-cbid', $network_setting );
141
142 return empty( $setting ) ? $network_setting : $setting;
143 }
144
145 /**
146 * @return string
147 */
148 public static function get_cookie_blocking_mode() {
149 $allowed_modes = array( 'auto', 'manual' );
150 $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' );
151 $setting = (string) get_option( 'cookiebot-cookie-blocking-mode', $network_setting );
152
153 return in_array( $setting, $allowed_modes, true ) ? $setting : 'manual';
154 }
155
156 /**
157 * @return bool
158 */
159 public static function check_network_auto_blocking_mode() {
160 $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode' );
161
162 return $network_setting === 'auto' ? true : false;
163 }
164
165 /**
166 * Cookiebot_WP Check if Cookiebot is active in admin
167 *
168 * @version 3.1.0
169 * @since 3.1.0
170 */
171 public static function cookiebot_disabled_in_admin() {
172 if ( is_multisite() && get_site_option( 'cookiebot-nooutput-admin', false ) ) {
173 return true;
174 } elseif ( get_option( 'cookiebot-nooutput-admin', false ) ) {
175 return true;
176 }
177
178 return false;
179 }
180
181 /**
182 * Cookiebot_WP Set default options
183 *
184 * @version 4.2.5
185 * @since 4.2.5
186 */
187 private function set_default_options() {
188 $options = array(
189 'cookiebot-nooutput-admin' => '1',
190 'cookiebot-gcm' => '1',
191 );
192
193 foreach ( $options as $option => $default ) {
194 if ( get_option( $option ) === false && ! get_option( $option . '-first-run' ) ) {
195 update_option( $option, $default );
196 }
197
198 if ( ( get_option( $option ) || get_option( $option ) !== false ) && ! get_option( $option . '-first-run' ) ) {
199 update_option( $option . '-first-run', '1' );
200 }
201 }
202 }
203
204 /**
205 * Cookiebot_WP Delay recommendation notice 1 day after first activation
206 *
207 * @version 4.2.5
208 * @since 4.2.5
209 */
210 private function delay_notice_recommendation_on_first_activation() {
211 // Check if recommendation notice delay option exists
212 if ( get_option( Cookiebot_Recommendation_Notice::COOKIEBOT_RECOMMENDATION_OPTION_KEY, false ) === false ) {
213 // Delay in 1 day
214 add_option( Cookiebot_Recommendation_Notice::COOKIEBOT_RECOMMENDATION_OPTION_KEY, strtotime( '+1 day' ) );
215 }
216 }
217
218 public function set_settings_action_link( $actions ) {
219 $cblinks = array(
220 '<a href="' . admin_url( 'admin.php?page=cookiebot' ) . '">' . esc_html__( 'Dashboard', 'cookiebot' ) . '</a>',
221 );
222 $actions = array_merge( $actions, $cblinks );
223 return $actions;
224 }
225
226 /**
227 * @return string
228 */
229 public static function get_manager_language() {
230 $locale = get_locale();
231 $supported_langs = array(
232 'de_DE' => 'de',
233 'da_DK' => 'da',
234 'fr_FR' => 'fr',
235 'it_IT' => 'it',
236 'es_ES' => 'es',
237 );
238
239 return array_key_exists( $locale, $supported_langs ) ? $supported_langs[ $locale ] : esc_html( 'en' );
240 }
241 }
242