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 / settings / pages / Debug_Page.php
cookiebot / src / settings / pages Last commit date
Dashboard_Page.php 3 years ago Debug_Page.php 2 years ago Gcm_Page.php 2 years ago Gtm_Page.php 3 years ago Iab_Page.php 2 years ago Legislations_Page.php 4 years ago Multiple_Page.php 3 years ago Settings_Page.php 3 years ago Settings_Page_Interface.php 3 years ago Support_Page.php 3 years ago
Debug_Page.php
276 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 .= 'Multiple banners: ' . $this->print_option_enabled( 'cookiebot-multiple-config' ) . "\n";
103 $debug_output .= $this->print_multiple_configuration_banners();
104 $debug_output .= 'Add async/defer to banner tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-uc-attribute' ) . "\n";
105 $debug_output .= 'Add async/defer to declaration tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-cd-attribute' ) . "\n";
106 $debug_output .= 'Auto update: ' . $this->print_option_enabled( 'cookiebot-autoupdate' ) . "\n";
107 $debug_output .= 'Hide Cookie Popup: ' . $this->print_option_active( 'cookiebot-nooutput' ) . "\n";
108 $debug_output .= 'Disable Cookiebot in WP Admin: ' . $this->print_option_active( 'cookiebot-nooutput-admin' ) . "\n";
109 $debug_output .= 'Enable Cookiebot on front end while logged in: ' . $this->print_option_active( 'cookiebot-output-logged-in' ) . "\n";
110 $debug_output .= 'List of ignored javascript files: ' . $this->get_ignored_scripts() . "\n";
111 $debug_output .= 'Banner tag: ' . $cookiebot_javascript_helper->include_cookiebot_js( true ) . "\n";
112 $debug_output .= 'Declaration tag: ' . Cookiebot_Declaration_Shortcode::show_declaration() . "\n";
113
114 if ( get_option( 'cookiebot-gtm' ) !== false ) {
115 $debug_output .= 'GTM tag: ' . $cookiebot_javascript_helper->include_google_tag_manager_js( true ) . "\n";
116 }
117
118 if ( get_option( 'cookiebot-gcm' ) !== false ) {
119 $debug_output .= 'GCM tag: ' . $cookiebot_javascript_helper->include_google_consent_mode_js( true ) . "\n";
120 }
121
122 $debug_output .= $this->print_wp_consent_level_api_mapping();
123 $debug_output .= $this->print_activated_addons();
124 $debug_output .= $this->print_activated_plugins();
125
126 $debug_output .= "\n##### Debug Information END #####";
127
128 return $debug_output;
129 }
130
131 /**
132 * Print the value of the option if it's not empty.
133 *
134 * @param string $option_name Name of the option to print.
135 *
136 * @return string
137 */
138 private function print_option_if_not_empty( $option_name ) {
139 $option_value = get_option( $option_name );
140 return $option_value !== '' ? $option_value : 'None';
141 }
142
143 /**
144 * Print "Enabled" or "Not enabled" depending on the option value. Option value should be "1" or "0".
145 *
146 * @param string $option_name Name of the option to check.
147 *
148 * @return string
149 */
150 private function print_option_enabled( $option_name ) {
151 return $this->print_option_active( $option_name, 'Enabled', 'Not enabled' );
152 }
153
154 /**
155 * Print "Yes" or "No" depending on the option value. Option value should be "1" or "0". If <b>$active_text</b> or
156 * <b>$disabled_text</b> is set, it will be used instead of default values "Yes" or "No".
157 *
158 * @param string $option_name Name of the option to check.
159 * @param string $active_text (Optional) Text to print if option is active. Default is "Yes".
160 * @param string $disabled_text (Optional) Text to print if option is disabled. Default is "No".
161 *
162 * @return string
163 */
164 private function print_option_active( $option_name, $active_text = 'Yes', $disabled_text = 'No' ) {
165 return get_option( $option_name ) === '1' ? $active_text : $disabled_text;
166 }
167
168 /**
169 * Render debug information about WP Consent Level API mapping.
170 *
171 * @return string
172 */
173 private function print_wp_consent_level_api_mapping() {
174 $output = '';
175
176 $consent_api_helper = new Consent_API_Helper();
177
178 if ( $consent_api_helper->is_wp_consent_api_active() ) {
179 $output .= "\n--- WP Consent Level API Mapping ---\n";
180 $output .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous' . "\n";
181 $map = $consent_api_helper->get_wp_consent_api_mapping();
182 foreach ( $map as $key => $value ) {
183 $output .= strtoupper( str_replace( ';', ', ', $key ) ) . ' => ';
184 $output .= 'F=1, ';
185 $output .= 'P=' . $value['preferences'] . ', ';
186 $output .= 'M=' . $value['marketing'] . ', ';
187 $output .= 'S=' . $value['statistics'] . ', ';
188 $output .= 'SA=' . $value['statistics-anonymous'] . "\n";
189 }
190 }
191
192 return $output;
193 }
194
195 private function print_multiple_configuration_banners() {
196 $secondary_id = get_option( 'cookiebot-second-banner-id' );
197 $secondary_regions = get_option( 'cookiebot-second-banner-regions' );
198 $banners = get_option( 'cookiebot-multiple-banners' );
199 $output = '';
200
201 if ( ! empty( $banners ) ) {
202 $counter = 1;
203 $output .= "\n--- Multiple Configuration Banners ---\n";
204 if ( ! empty( $secondary_id ) ) {
205 $output .= '-Banner: ' . $counter . " -\n";
206 $output .= 'Id: ' . $secondary_id . " \n";
207 $output .= 'Regions: ' . $secondary_regions . " \n\n";
208 $counter++;
209 }
210 foreach ( $banners as $banner ) {
211 $output .= '-Banner: ' . $counter . " -\n";
212 $output .= 'Id: ' . $banner['group'] . " \n";
213 $output .= 'Regions: ' . $banner['region'] . " \n\n";
214 $counter++;
215 }
216 }
217
218 return $output;
219 }
220
221 private function print_tcf_version() {
222 $version = get_option( 'cookiebot-tcf-version' );
223 return ( empty( $version ) || $version === 'IAB' ) ? '2.0' : $version;
224 }
225
226 /**
227 * Print information about activated cookiebot addons.
228 *
229 * @return string
230 */
231 private function print_activated_addons() {
232 $output = '';
233
234 try {
235 $cookiebot_addons = new Cookiebot_Addons();
236 /** @var Settings_Service_Interface $settings_service */
237 $settings_service = $cookiebot_addons->container->get( 'Settings_Service_Interface' );
238 $addons = $settings_service->get_active_addons();
239 $output .= "\n--- Activated Cookiebot Addons ---\n";
240 /** @var Base_Cookiebot_Addon $addon */
241 foreach ( $addons as $addon ) {
242 $output .= $addon::ADDON_NAME . ' (' . implode( ', ', $addon->get_cookie_types() ) . ")\n";
243 }
244 } catch ( Exception $exception ) {
245 $output .= PHP_EOL . '--- Cookiebot Addons could not be activated ---' . PHP_EOL;
246 $output .= $exception->getMessage() . PHP_EOL;
247 }
248
249 return $output;
250 }
251
252 /**
253 * Print information about activated plugins
254 *
255 * @return string
256 */
257 private function print_activated_plugins() {
258 if ( ! function_exists( 'get_plugins' ) ) {
259 include_once ABSPATH . 'wp-admin/includes/plugin.php';
260 }
261
262 $plugins = get_plugins();
263 $active_plugins = get_option( 'active_plugins' );
264
265 $output = "\n--- Activated Plugins ---\n";
266
267 foreach ( $active_plugins as $plugin_key ) {
268 if ( $plugin_key !== 'cookiebot/cookiebot.php' ) {
269 $output .= $plugins[ $plugin_key ]['Name'] . ' (Version: ' . $plugins[ $plugin_key ]['Version'] . ")\n";
270 }
271 }
272
273 return $output;
274 }
275 }
276