PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.5.0
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.5.0
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 / settings / pages / Debug_Page.php
cookiebot / src / settings / pages Last commit date
Additional_Page.php 1 year ago Dashboard_Page.php 1 year ago Debug_Page.php 1 year ago Embeddings_Page.php 1 year ago Gcm_Page.php 1 year ago General_Page.php 1 year ago Gtm_Page.php 1 year ago Iab_Page.php 1 year ago Multiple_Page.php 1 year ago Settings_Page.php 1 year ago Settings_Page_Interface.php 1 year ago Support_Page.php 1 year ago
Debug_Page.php
326 lines
1 <?php
2
3 namespace cybot\cookiebot\settings\pages;
4
5 use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon;
6 use cybot\cookiebot\addons\Cookiebot_Addons;
7 use cybot\cookiebot\lib\Consent_API_Helper;
8 use cybot\cookiebot\lib\Cookiebot_Frame;
9 use cybot\cookiebot\lib\Cookiebot_Javascript_Helper;
10 use cybot\cookiebot\lib\Settings_Service_Interface;
11 use cybot\cookiebot\lib\Cookiebot_WP;
12 use cybot\cookiebot\shortcode\Cookiebot_Declaration_Shortcode;
13 use InvalidArgumentException;
14 use RuntimeException;
15 use function cybot\cookiebot\lib\asset_url;
16 use function cybot\cookiebot\lib\include_view;
17 use Exception;
18
19 class Debug_Page implements Settings_Page_Interface {
20
21
22 const ADMIN_SLUG = 'cookiebot_debug';
23
24 public function menu() {
25 if ( Cookiebot_Frame::is_cb_frame_type() !== 'empty' ) {
26 add_submenu_page(
27 'cookiebot',
28 __( 'Debug info', 'cookiebot' ),
29 __( 'Debug info', 'cookiebot' ),
30 'manage_options',
31 self::ADMIN_SLUG,
32 array( $this, 'display' ),
33 25
34 );
35 }
36 }
37
38 /**
39 * @throws InvalidArgumentException
40 */
41 public function display() {
42 wp_enqueue_script(
43 'cookiebot-debug-page-js',
44 asset_url( 'js/backend/debug-page.js' ),
45 null,
46 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
47 true
48 );
49
50 $style_sheets = array(
51 array( 'cookiebot-debug-css', 'css/backend/debug_info.css' ),
52 );
53
54 foreach ( $style_sheets as $style ) {
55 wp_enqueue_style(
56 $style[0],
57 asset_url( $style[1] ),
58 null,
59 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
60 );
61 }
62
63 $debug_output = $this->prepare_debug_data();
64
65 include_view( Cookiebot_Frame::get_view_path() . 'debug-page.php', array( 'debug_output' => $debug_output ) );
66 }
67
68 private function get_ignored_scripts() {
69 $ignored_scripts = get_option( 'cookiebot-ignore-scripts' );
70
71 $ignored_scripts = array_map(
72 function ( $ignore_tag ) {
73 return trim( $ignore_tag );
74 },
75 explode( PHP_EOL, $ignored_scripts )
76 );
77
78 $ignored_scripts = apply_filters( 'cybot_cookiebot_ignore_scripts', $ignored_scripts );
79
80 return implode( ', ', $ignored_scripts );
81 }
82
83 /**
84 * @throws InvalidArgumentException
85 */
86 public function prepare_debug_data() {
87 global $wpdb;
88
89 $cookiebot_javascript_helper = new Cookiebot_Javascript_Helper();
90
91 $debug_output = '';
92 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
93 $debug_output .= '##### Debug Information for ' . get_site_url() . ' generated at ' . date( 'c' ) . " #####\n\n";
94 $debug_output .= 'WordPress Version: ' . get_bloginfo( 'version' ) . "\n";
95 $debug_output .= 'WordPress Language: ' . get_bloginfo( 'language' ) . "\n";
96 $debug_output .= 'PHP Version: ' . phpversion() . "\n";
97 $debug_output .= 'MySQL Version: ' . $wpdb->db_version() . "\n";
98 $debug_output .= "\n--- Cookiebot Information ---\n";
99 $debug_output .= 'Plugin Version: ' . Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION . "\n";
100 $debug_output .= 'Settings ID: ' . Cookiebot_WP::get_cbid() . "\n";
101 $debug_output .= 'Blocking mode: ' . get_option( 'cookiebot-cookie-blocking-mode' ) . "\n";
102 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
103 $debug_output .= 'Language: ' . get_option( 'cookiebot-language' ) . "\n";
104 $debug_output .= 'Frontend Language: ' . $this->print_option_enabled( 'cookiebot-front-language' ) . "\n";
105 }
106 $debug_output .= 'IAB: ' . $this->print_option_enabled( 'cookiebot-iab' ) . "\n";
107 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
108 $debug_output .= 'TCF version: ' . $this->print_tcf_version() . "\n";
109 $debug_output .= 'TCF tag: ' . $cookiebot_javascript_helper->include_publisher_restrictions_js( true ) . "\n";
110 $debug_output .= 'Multiple banners: ' . $this->print_option_enabled( 'cookiebot-multiple-config' ) . "\n";
111 $debug_output .= $this->print_multiple_configuration_banners();
112 $debug_output .= 'Add async/defer to banner tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-uc-attribute' ) . "\n";
113 $debug_output .= 'Add async/defer to declaration tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-cd-attribute' ) . "\n";
114 }
115 $debug_output .= 'Auto update: ' . $this->print_option_enabled( 'cookiebot-autoupdate' ) . "\n";
116 $debug_output .= 'Show banner on site: ' . $this->print_option_active( 'cookiebot-banner-enabled' ) . "\n";
117 $debug_output .= 'Hide Cookie Popup: ' . $this->print_option_active( 'cookiebot-nooutput' ) . "\n";
118 $debug_output .= 'Enable Cookiebot on front end while logged in: ' . $this->print_option_active( 'cookiebot-output-logged-in' ) . "\n";
119 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
120 $debug_output .= 'List of ignored javascript files: ' . $this->get_ignored_scripts() . "\n";
121 $debug_output .= 'Banner tag: ' . "\n" . $cookiebot_javascript_helper->include_cookiebot_js( true ) . "\n";
122 $debug_output .= 'Declaration tag: ' . Cookiebot_Declaration_Shortcode::show_declaration() . "\n";
123 } else {
124 $debug_output .= 'Banner tag: ' . "\n" . $cookiebot_javascript_helper->include_uc_cmp_js( true ) . "\n";
125 }
126
127 if ( get_option( 'cookiebot-gtm' ) !== false ) {
128 $debug_output .= 'GTM tag: ' . $cookiebot_javascript_helper->include_google_tag_manager_js( true ) . "\n";
129 }
130
131 if ( get_option( 'cookiebot-gcm' ) === '1' ) {
132 $debug_output .= 'GCM tag: ' . $cookiebot_javascript_helper->include_google_consent_mode_js( true ) . "\n";
133 }
134
135 if ( is_multisite() ) {
136 $debug_output .= $this->print_multisite_network_settings();
137 }
138
139 $debug_output .= $this->print_wp_consent_level_api_mapping();
140 $debug_output .= $this->print_activated_addons();
141 $debug_output .= $this->print_activated_plugins();
142
143 $debug_output .= "\n##### Debug Information END #####";
144
145 return $debug_output;
146 }
147
148 /**
149 * Print the value of the option if it's not empty.
150 *
151 * @param string $option_name Name of the option to print.
152 *
153 * @return string
154 */
155 private function print_option_if_not_empty( $option_name, $is_multisite = false ) {
156 $option_value = $is_multisite ? get_site_option( $option_name ) : get_option( $option_name );
157 return $option_value !== '' ? $option_value : 'None';
158 }
159
160 /**
161 * Print "Enabled" or "Not enabled" depending on the option value. Option value should be "1" or "0".
162 *
163 * @param string $option_name Name of the option to check.
164 * @param bool $is_multisite Is multisite option.
165 *
166 * @return string
167 */
168 private function print_option_enabled( $option_name, $is_multisite = false ) {
169 return $this->print_option_active( $option_name, $is_multisite, 'Enabled', 'Not enabled' );
170 }
171
172 /**
173 * Print "Yes" or "No" depending on the option value. Option value should be "1" or "0". If <b>$active_text</b> or
174 * <b>$disabled_text</b> is set, it will be used instead of default values "Yes" or "No".
175 *
176 * @param string $option_name Name of the option to check.
177 * @param bool $is_multisite Is multisite option.
178 * @param string $active_text (Optional) Text to print if option is active. Default is "Yes".
179 * @param string $disabled_text (Optional) Text to print if option is disabled. Default is "No".
180 *
181 * @return string
182 */
183 private function print_option_active( $option_name, $is_multisite = false, $active_text = 'Yes', $disabled_text = 'No' ) {
184 if ( $is_multisite ) {
185 return get_site_option( $option_name ) === '1' ? $active_text : $disabled_text;
186 }
187 return get_option( $option_name ) === '1' ? $active_text : $disabled_text;
188 }
189
190 /**
191 * Render debug information about WP Consent Level API mapping.
192 *
193 * @return string
194 */
195 private function print_wp_consent_level_api_mapping() {
196 $output = '';
197
198 $consent_api_helper = new Consent_API_Helper();
199
200 if ( $consent_api_helper->is_wp_consent_api_active() ) {
201 $output .= "\n--- WP Consent API Mapping ---\n";
202 $map = $consent_api_helper->get_wp_consent_api_mapping();
203 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
204 $output .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous' . "\n";
205 foreach ( $map as $key => $value ) {
206 $output .= strtoupper( str_replace( ';', ', ', $key ) ) . ' => ';
207 $output .= 'F=1, ';
208 $output .= 'P=' . $value['preferences'] . ', ';
209 $output .= 'M=' . $value['marketing'] . ', ';
210 $output .= 'S=' . $value['statistics'] . ', ';
211 $output .= 'SA=' . $value['statistics-anonymous'] . "\n";
212 }
213 } else {
214 foreach ( $map as $key => $value ) {
215 $output .= $key . ' => ' . $value . "\n";
216 }
217 }
218 }
219
220 return $output;
221 }
222
223 private function print_multiple_configuration_banners() {
224 $secondary_id = get_option( 'cookiebot-second-banner-id' );
225 $secondary_regions = get_option( 'cookiebot-second-banner-regions' );
226 $banners = get_option( 'cookiebot-multiple-banners' );
227 $output = '';
228
229 if ( ! empty( $banners ) ) {
230 $counter = 1;
231 $output .= "\n--- Multiple Configuration Banners ---\n";
232 if ( ! empty( $secondary_id ) ) {
233 $output .= '-Banner: ' . $counter . " -\n";
234 $output .= 'Id: ' . $secondary_id . " \n";
235 $output .= 'Regions: ' . $secondary_regions . " \n\n";
236 ++$counter;
237 }
238 foreach ( $banners as $banner ) {
239 $output .= '-Banner: ' . $counter . " -\n";
240 $output .= 'Id: ' . $banner['group'] . " \n";
241 $output .= 'Regions: ' . $banner['region'] . " \n\n";
242 ++$counter;
243 }
244 }
245
246 return $output;
247 }
248
249 private function print_tcf_version() {
250 $version = get_option( 'cookiebot-tcf-version' );
251 return ( empty( $version ) || $version === 'IAB' ) ? '2.0' : $version;
252 }
253
254 /**
255 * Print information about activated cookiebot addons.
256 *
257 * @return string
258 */
259 private function print_activated_addons() {
260 $output = '';
261
262 if ( Cookiebot_Frame::is_cb_frame_type() === false ) {
263 return $output;
264 }
265
266 try {
267 $cookiebot_addons = new Cookiebot_Addons();
268 /** @var Settings_Service_Interface $settings_service */
269 $settings_service = $cookiebot_addons->container->get( 'Settings_Service_Interface' );
270 $addons = $settings_service->get_active_addons();
271 $output .= "\n--- Activated Cookiebot Addons ---\n";
272 /** @var Base_Cookiebot_Addon $addon */
273 foreach ( $addons as $addon ) {
274 $output .= $addon::ADDON_NAME . ' (' . implode( ', ', $addon->get_cookie_types() ) . ")\n";
275 }
276 } catch ( Exception $exception ) {
277 $output .= PHP_EOL . '--- Cookiebot Addons could not be activated ---' . PHP_EOL;
278 $output .= $exception->getMessage() . PHP_EOL;
279 }
280
281 return $output;
282 }
283
284 /**
285 * Print information about activated plugins
286 *
287 * @return string
288 */
289 private function print_activated_plugins() {
290 if ( ! function_exists( 'get_plugins' ) ) {
291 include_once ABSPATH . 'wp-admin/includes/plugin.php';
292 }
293
294 $plugins = get_plugins();
295 $active_plugins = get_option( 'active_plugins' );
296
297 $output = "\n--- Activated Plugins ---\n";
298
299 foreach ( $active_plugins as $plugin_key ) {
300 if ( $plugin_key !== 'cookiebot/cookiebot.php' ) {
301 $output .= $plugins[ $plugin_key ]['Name'] . ' (Version: ' . $plugins[ $plugin_key ]['Version'] . ")\n";
302 }
303 }
304
305 return $output;
306 }
307
308 /**
309 * Print information about activated plugins
310 *
311 * @return string
312 */
313 private function print_multisite_network_settings() {
314 $output = "\n--- Cookiebot Multisite Information ---\n";
315 $output .= 'Cookiebot Network ID: ' . $this->print_option_if_not_empty( 'cookiebot-cbid', true ) . "\n";
316 $output .= 'Network Blocking mode: ' . get_site_option( 'cookiebot-cookie-blocking-mode' ) . "\n";
317 $output .= 'Network Add async/defer to banner tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-uc-attribute', true ) . "\n";
318 $output .= 'Network Add async/defer to declaration tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-cd-attribute', true ) . "\n";
319 $output .= 'Network Auto update: ' . $this->print_option_enabled( 'cookiebot-autoupdate', true ) . "\n";
320 $output .= 'Network Hide Cookie Popup: ' . $this->print_option_enabled( 'cookiebot-nooutput', true ) . "\n";
321 $output .= 'Network Disable Cookiebot in WP Admin: ' . $this->print_option_active( 'cookiebot-nooutput-admin', true ) . "\n";
322
323 return $output;
324 }
325 }
326