PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / logs / LoggingCapabilityDiagnostics.php

LoggingCapabilityDiagnostics.php in 404 Solution trunk, at includes/logs/LoggingCapabilityDiagnostics.php

43 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 // allow-no-test-found: covered by tests/LoggingTest.php through ABJ_404_Solution_Logging::logUserCapabilities().
9
10 /**
11 * Builds the current-user capability diagnostic line for the debug log.
12 *
13 * This class owns presentation of the capability snapshot only. The caller is
14 * responsible for writing the returned line so normal debug-mode gating and
15 * write-time PII redaction still apply in one place.
16 */
17 class ABJ_404_Solution_LoggingCapabilityDiagnostics {
18
19 /**
20 * @param string $msg Operator-supplied context to include with the snapshot.
21 * @return string
22 */
23 public function format(string $msg): string {
24 $f = abj_service('functions');
25 $user = wp_get_current_user();
26 $usercaps = $f->str_replace(',"', ', "', wp_kses_post((string)json_encode($user->get_role_caps())));
27
28 $userIsPluginAdminStr = "false";
29 if (abj_service('admin_access_policy')->isPluginAdmin()) {
30 $userIsPluginAdminStr = "true";
31 }
32
33 return "User caps msg: " . esc_html($msg == '' ? '(none)' : $msg) . ", is_admin(): " . is_admin() .
34 ", current_user_can('manage_options'): " . current_user_can('manage_options') .
35 ", current_user_can('administrator'): " . current_user_can('administrator') .
36 ", userIsPluginAdmin(): " . $userIsPluginAdminStr .
37 ", user_login: " . esc_html($user->user_login ?? '(none)') .
38 ", user caps: " . wp_kses_post((string)json_encode($user->caps)) . ", get_role_caps: " .
39 $usercaps . ", WP ver: " . get_bloginfo('version') . ", mbstring: " .
40 (extension_loaded('mbstring') ? 'true' : 'false');
41 }
42 }
43