PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.4.1
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.4.1
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 1 year ago script_loader_tag 1 year ago traits 1 year ago Consent_API_Helper.php 1 year ago Cookie_Consent.php 1 year ago Cookie_Consent_Interface.php 1 year ago Cookiebot_Activated.php 1 year 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 1 year ago Cookiebot_Review.php 1 year ago Cookiebot_WP.php 1 year 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 1 year ago
Cookiebot_WP.php
267 lines
1 <?php
2
3 namespace cybot\cookiebot\lib;
4
5 use cybot\cookiebot\addons\Cookiebot_Addons;
6 use cybot\cookiebot\admin_notices\Cookiebot_Notices;
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\shortcode\Cookiebot_Embedding_Shortcode;
11 use cybot\cookiebot\widgets\Dashboard_Widget_Cookiebot_Status;
12 use DomainException;
13 use RuntimeException;
14
15 class Cookiebot_WP {
16
17 const COOKIEBOT_PLUGIN_VERSION = '4.4.1';
18 const COOKIEBOT_MIN_PHP_VERSION = '5.6.0';
19
20 /**
21 * @var Cookiebot_WP The single instance of the class
22 * @since 1.0.0
23 */
24 private static $instance = null;
25
26 /**
27 * Main Cookiebot_WP Instance
28 *
29 * Ensures only one instance of Cookiebot_WP is loaded or can be loaded.
30 *
31 * @return Cookiebot_WP - Main instance
32 * @throws RuntimeException
33 * @version 1.0.0
34 * @since 1.0.0
35 * @static
36 */
37 public static function instance() {
38 if ( is_null( self::$instance ) ) {
39 self::$instance = new self();
40 }
41
42 return self::$instance;
43 }
44
45 /**
46 * Cookiebot_WP Constructor.
47 *
48 * @throws RuntimeException
49 * @since 1.0.0
50 * @access public
51 * @version 2.1.4
52 */
53 public function __construct() {
54 $this->throw_exception_if_php_version_is_incompatible();
55 $this->cookiebot_init();
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 add_action( 'init', array( $this, 'cookiebot_load_textdomain' ) );
77
78 if ( is_admin() ) {
79 ( new Menu_Settings() )->add_menu();
80 if ( is_multisite() && is_plugin_active_for_network( 'cookiebot/cookiebot.php' ) ) {
81 ( new Network_Menu_Settings() )->add_menu();
82 }
83 ( new Dashboard_Widget_Cookiebot_Status() )->register_hooks();
84 ( new Cookiebot_Notices() )->register_hooks();
85 ( new Cookiebot_Review() )->register_hooks();
86 }
87
88 ( new Consent_API_Helper() )->register_hooks();
89 ( new Cookiebot_Javascript_Helper() )->register_hooks();
90 ( new Cookiebot_Embedding_Shortcode() )->register_hooks();
91 ( new Cookiebot_Automatic_Updates() )->register_hooks();
92 ( new Widgets() )->register_hooks();
93 ( new Cookiebot_Gutenberg_Declaration_Block() )->register_hooks();
94 ( new WP_Rocket_Helper() )->register_hooks();
95
96 $this->set_default_options();
97 ( new Cookiebot_Admin_Links() )->register_hooks();
98 }
99
100 /**
101 * Returns true if an user is logged in and has an edit_themes capability
102 *
103 * @return bool
104 *
105 * @since 3.3.1
106 * @version 3.4.1
107 */
108 public static function can_current_user_edit_theme() {
109 if ( is_user_logged_in() &&
110 (
111 current_user_can( 'edit_themes' ) ||
112 current_user_can( 'edit_pages' ) ||
113 current_user_can( 'edit_posts' )
114 )
115 ) {
116 return true;
117 }
118
119 return false;
120 }
121
122 /**
123 * Loads translations textdomain
124 *
125 * @return void
126 */
127 public function cookiebot_load_textdomain() {
128 load_textdomain(
129 'cookiebot',
130 CYBOT_COOKIEBOT_PLUGIN_DIR . 'langs/cookiebot-' . get_locale() . '.mo'
131 );
132 load_plugin_textdomain( 'cookiebot', false, dirname( plugin_basename( __FILE__ ) ) . '/langs' );
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_network_cbid() {
149 return get_site_option( 'cookiebot-cbid', '' );
150 }
151
152 /**
153 * @return string
154 */
155 public static function get_cookie_blocking_mode() {
156 $allowed_modes = array( 'auto', 'manual' );
157 $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode', 'manual' );
158 $setting = $network_setting === 'manual' ?
159 (string) get_option( 'cookiebot-cookie-blocking-mode', $network_setting ) :
160 $network_setting;
161
162 return in_array( $setting, $allowed_modes, true ) ? $setting : 'manual';
163 }
164
165 /**
166 * @return bool
167 */
168 public static function check_network_auto_blocking_mode() {
169 $network_setting = (string) get_site_option( 'cookiebot-cookie-blocking-mode' );
170
171 return $network_setting === 'auto' ? true : false;
172 }
173
174 /**
175 * @return string
176 */
177 public static function get_cookie_categories_status() {
178 return self::get_cookie_blocking_mode() === 'auto' ? 'disabled' : '';
179 }
180
181 /**
182 * @return bool
183 */
184 public static function is_cookie_category_selected( $option, $category ) {
185 $categories = get_option( $option );
186 if ( ! $categories || ! is_array( $categories ) ) {
187 return false;
188 }
189
190 return in_array( $category, $categories, true );
191 }
192
193 /**
194 * Cookiebot_WP Check if Cookiebot is active in admin
195 *
196 * @version 4.2.8
197 * @since 3.1.0
198 */
199 public static function cookiebot_disabled_in_admin() {
200 if ( ( is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) ||
201 ( ! is_network_admin() && get_site_option( 'cookiebot-nooutput-admin', false ) ) ||
202 ( ! is_network_admin() && get_option( 'cookiebot-nooutput-admin', false ) ) ) {
203 return true;
204 }
205
206 return false;
207 }
208
209 /**
210 * Cookiebot_WP Set default options
211 *
212 * @version 4.2.5
213 * @since 4.2.5
214 */
215 private function set_default_options() {
216 $options = array(
217 'cookiebot-nooutput-admin' => '1',
218 'cookiebot-gcm' => '1',
219 );
220
221 foreach ( $options as $option => $default ) {
222 if ( get_option( $option ) === false && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) {
223 update_option( $option, $default );
224 }
225
226 if ( ( get_option( $option ) || get_option( $option ) !== false ) && ! get_option( $option . self::OPTION_FIRST_RUN_SUFFIX ) ) {
227 update_option( $option . self::OPTION_FIRST_RUN_SUFFIX, '1' );
228 }
229 }
230
231 self::set_tcf_version();
232 }
233
234 private static function set_tcf_version() {
235 $iab_version = get_option( 'cookiebot-tcf-version' );
236 if ( empty( $iab_version ) || $iab_version === 'IAB' ) {
237 update_option( 'cookiebot-tcf-version', 'TCFv2.2' );
238 }
239 }
240
241 public function set_settings_action_link( $actions ) {
242 $cblinks = array(
243 '<a href="' . esc_url( add_query_arg( 'page', 'cookiebot', admin_url( 'admin.php' ) ) ) . '">' . esc_html__( 'Dashboard', 'cookiebot' ) . '</a>',
244 );
245 $actions = array_merge( $actions, $cblinks );
246 return $actions;
247 }
248
249 /**
250 * @return string
251 */
252 public static function get_manager_language() {
253 $locale = get_locale();
254 $supported_langs = array(
255 'de_DE' => 'de',
256 'da_DK' => 'da',
257 'fr_FR' => 'fr',
258 'it_IT' => 'it',
259 'es_ES' => 'es',
260 );
261
262 return array_key_exists( $locale, $supported_langs ) ? $supported_langs[ $locale ] : esc_html( 'en' );
263 }
264
265 const OPTION_FIRST_RUN_SUFFIX = '-first-run';
266 }
267