| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Generates random report identifiers for queued feedback envelopes. |
| 9 |
*/ |
| 10 |
class ABJ_404_Solution_FeedbackReportUuid { |
| 11 |
|
| 12 |
public static function generate(): string { |
| 13 |
try { |
| 14 |
$data = random_bytes(16); |
| 15 |
// allow-silent-catch: random_bytes only throws when CSPRNG unavailable; fallback to wp_generate_password / mt_rand still produces a valid transient key |
| 16 |
} catch (\Throwable $e) { |
| 17 |
$data = ''; |
| 18 |
if (function_exists('wp_generate_password')) { |
| 19 |
$data = (string)wp_generate_password(16, true, true); |
| 20 |
$data = substr($data . str_repeat("\0", 16), 0, 16); |
| 21 |
} |
| 22 |
if ($data === '' || strlen($data) < 16) { |
| 23 |
$data = str_pad((string)mt_rand(), 16, "\0"); |
| 24 |
$data = substr($data, 0, 16); |
| 25 |
} |
| 26 |
} |
| 27 |
$data[6] = chr((ord($data[6]) & 0x0f) | 0x40); |
| 28 |
$data[8] = chr((ord($data[8]) & 0x3f) | 0x80); |
| 29 |
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); |
| 30 |
} |
| 31 |
} |
| 32 |
|