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