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