| 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 |
|