Make WordPress Core

Ticket #28633: 28633.diff

File 28633.diff, 2.5 KB (added by dd32, 10 years ago)
  • src/wp-includes/pluggable.php

    if ( !function_exists('wp_rand') ) : 
    21312131/**
    21322132 * Generates a random number
    21332133 *
    21342134 * @since 2.6.2
    21352135 *
    21362136 * @global string $rnd_value
    21372137 * @staticvar string $seed
    21382138 *
    21392139 * @param int $min Lower limit for the generated number
    21402140 * @param int $max Upper limit for the generated number
    21412141 * @return int A random number between min and max
    21422142 */
    21432143function wp_rand( $min = 0, $max = 0 ) {
    21442144        global $rnd_value;
    21452145
     2146        // We're only dealing with int's
     2147        $min = (int) $min;
     2148        $max = (int) $max;
     2149
     2150        // Use an external source?
     2151        static $external_rand_source_available = true;
     2152        if ( $external_rand_source_available ) {
     2153                try {
     2154                        $val = random_int( min( $min, $max ), max( $min, $max ) );
     2155                        if ( false !== $val ) {
     2156                                return abs( $val );
     2157                        } else {
     2158                                $external_rand_source_available = false;
     2159                        }
     2160                } catch ( Throwable $t ) {
     2161                        $external_rand_source_available = false;
     2162                } catch ( Exception $e ) {
     2163                        $external_rand_source_available = false;
     2164                }
     2165        }
     2166
    21462167        // Reset $rnd_value after 14 uses
    21472168        // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    21482169        if ( strlen($rnd_value) < 8 ) {
    21492170                if ( defined( 'WP_SETUP_CONFIG' ) )
    21502171                        static $seed = '';
    21512172                else
    21522173                        $seed = get_transient('random_seed');
    21532174                $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed );
    21542175                $rnd_value .= sha1($rnd_value);
    21552176                $rnd_value .= sha1($rnd_value . $seed);
    21562177                $seed = md5($seed . $rnd_value);
    21572178                if ( ! defined( 'WP_SETUP_CONFIG' ) && ! defined( 'WP_INSTALLING' ) ) {
    21582179                        set_transient( 'random_seed', $seed );
    21592180                }
    21602181        }
  • src/wp-includes/compat.php

    function hash_equals( $a, $b ) { 
    248248
    249249        // Do not attempt to "optimize" this.
    250250        for ( $i = 0; $i < $a_length; $i++ ) {
    251251                $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] );
    252252        }
    253253
    254254        return $result === 0;
    255255}
    256256endif;
    257257
    258258// JSON_PRETTY_PRINT was introduced in PHP 5.4
    259259// Defined here to prevent a notice when using it with wp_json_encode()
    260260if ( ! defined( 'JSON_PRETTY_PRINT' ) ) {
    261261        define( 'JSON_PRETTY_PRINT', 128 );
    262262}
     263
     264if ( ! function_exists( 'random_int' ) ) {
     265        include ABSPATH . WPINC . '/random_compat/random.php';
     266}
     267 No newline at end of file