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