Skip to content

Commit 6f59851

Browse files
committed
Try falling back to random_int and only if it is not available, fallback to mt_rand.
1 parent 909b2ab commit 6f59851

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/wp-includes/functions.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7990,12 +7990,24 @@ function wp_raise_memory_limit( $context = 'admin' ) {
79907990
* Generates a random UUID (version 4).
79917991
*
79927992
* @since 4.7.0
7993-
* @since 7.0.0 Uses wp_rand instead of mt_rand if available.
7993+
* @since 7.0.0 Uses wp_rand if available.
79947994
*
79957995
* @return string UUID.
79967996
*/
79977997
function wp_generate_uuid4() {
7998-
$randomizer = function_exists( 'wp_rand' ) ? 'wp_rand' : 'mt_rand';
7998+
static $backup_randomizer = false;
7999+
$randomizer = function_exists( 'wp_rand' ) ? 'wp_rand' : $backup_randomizer;
8000+
8001+
if ( false === $randomizer ) {
8002+
try {
8003+
random_int( 0, 15705 );
8004+
$backup_randomizer = 'random_int';
8005+
} catch ( Exception $e ) {
8006+
$backup_randomizer = 'mt_rand';
8007+
}
8008+
$randomizer = $backup_randomizer;
8009+
}
8010+
79998011
return sprintf(
80008012
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
80018013
$randomizer( 0, 0xffff ),

0 commit comments

Comments
 (0)