Skip to content

Commit f02aa6d

Browse files
committed
Only use wp_rand if the function exists.
Prevents a fatal if this function is called before pluggable functions have been loaded. Props peterwilsoncc.
1 parent ebe961b commit f02aa6d

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/wp-includes/functions.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,20 +7952,22 @@ function wp_raise_memory_limit( $context = 'admin' ) {
79527952
* Generates a random UUID (version 4).
79537953
*
79547954
* @since 4.7.0
7955+
* @since 7.0.0 Uses wp_rand instead of mt_rand if available.
79557956
*
79567957
* @return string UUID.
79577958
*/
79587959
function wp_generate_uuid4() {
7960+
$randomizer = function_exists( 'wp_rand' ) ? 'wp_rand' : 'mt_rand';
79597961
return sprintf(
79607962
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
7961-
wp_rand( 0, 0xffff ),
7962-
wp_rand( 0, 0xffff ),
7963-
wp_rand( 0, 0xffff ),
7964-
wp_rand( 0, 0x0fff ) | 0x4000,
7965-
wp_rand( 0, 0x3fff ) | 0x8000,
7966-
wp_rand( 0, 0xffff ),
7967-
wp_rand( 0, 0xffff ),
7968-
wp_rand( 0, 0xffff )
7963+
$randomizer( 0, 0xffff ),
7964+
$randomizer( 0, 0xffff ),
7965+
$randomizer( 0, 0xffff ),
7966+
$randomizer( 0, 0x0fff ) | 0x4000,
7967+
$randomizer( 0, 0x3fff ) | 0x8000,
7968+
$randomizer( 0, 0xffff ),
7969+
$randomizer( 0, 0xffff ),
7970+
$randomizer( 0, 0xffff )
79697971
);
79707972
}
79717973

0 commit comments

Comments
 (0)