diff --git a/wp-includes/compat.php b/wp-includes/compat.php index ac78f7f9a3..60e8c0772b 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -8,8 +8,8 @@ // If gettext isn't available. if ( ! function_exists( '_' ) ) { - function _( $string ) { - return $string; + function _( $message ) { + return $message; } } @@ -49,24 +49,24 @@ if ( ! function_exists( 'mb_substr' ) ) : * * @see _mb_substr() * - * @param string $str The string to extract the substring from. - * @param int $start Position to being extraction from in `$str`. - * @param int|null $length Optional. Maximum number of characters to extract from `$str`. + * @param string $string The string to extract the substring from. + * @param int $start Position to being extraction from in `$string`. + * @param int|null $length Optional. Maximum number of characters to extract from `$string`. * Default null. * @param string|null $encoding Optional. Character encoding to use. Default null. * @return string Extracted substring. */ - function mb_substr( $str, $start, $length = null, $encoding = null ) { - return _mb_substr( $str, $start, $length, $encoding ); + function mb_substr( $string, $start, $length = null, $encoding = null ) { + return _mb_substr( $string, $start, $length, $encoding ); } endif; /** * Internal compat function to mimic mb_substr(). * - * Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit. - * For $encoding === UTF-8, the $str input is expected to be a valid UTF-8 byte sequence. - * The behavior of this function for invalid inputs is undefined. + * Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit. + * For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte + * sequence. The behavior of this function for invalid inputs is undefined. * * @ignore * @since 3.2.0 @@ -116,6 +116,7 @@ function _mb_substr( $str, $start, $length = null, $encoding = null ) { // Start with 1 element instead of 0 since the first thing we do is pop. $chars = array( '' ); + do { // We had some string left over from the last round, but we counted it in that last round. array_pop( $chars ); @@ -143,12 +144,12 @@ if ( ! function_exists( 'mb_strlen' ) ) : * * @see _mb_strlen() * - * @param string $str The string to retrieve the character length from. + * @param string $string The string to retrieve the character length from. * @param string|null $encoding Optional. Character encoding to use. Default null. - * @return int String length of `$str`. + * @return int String length of `$string`. */ - function mb_strlen( $str, $encoding = null ) { - return _mb_strlen( $str, $encoding ); + function mb_strlen( $string, $encoding = null ) { + return _mb_strlen( $string, $encoding ); } endif; @@ -156,7 +157,7 @@ endif; * Internal compat function to mimic mb_strlen(). * * Only understands UTF-8 and 8bit. All other character sets will be treated as 8bit. - * For $encoding === UTF-8, the `$str` input is expected to be a valid UTF-8 byte + * For `$encoding === UTF-8`, the `$str` input is expected to be a valid UTF-8 byte * sequence. The behavior of this function for invalid inputs is undefined. * * @ignore @@ -199,6 +200,7 @@ function _mb_strlen( $str, $encoding = null ) { // Start at 1 instead of 0 since the first thing we do is decrement. $count = 1; + do { // We had some string left over from the last round, but we counted it in that last round. $count--; @@ -235,16 +237,16 @@ if ( ! function_exists( 'hash_hmac' ) ) : * * @see _hash_hmac() * - * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. - * @param string $data Data to be hashed. - * @param string $key Secret key to use for generating the hash. - * @param bool $raw_output Optional. Whether to output raw binary data (true), - * or lowercase hexits (false). Default false. - * @return string|false The hash in output determined by `$raw_output`. False if `$algo` - * is unknown or invalid. + * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. + * @param string $data Data to be hashed. + * @param string $key Secret key to use for generating the hash. + * @param bool $binary Optional. Whether to output raw binary data (true), + * or lowercase hexits (false). Default false. + * @return string|false The hash in output determined by `$binary`. + * False if `$algo` is unknown or invalid. */ - function hash_hmac( $algo, $data, $key, $raw_output = false ) { - return _hash_hmac( $algo, $data, $key, $raw_output ); + function hash_hmac( $algo, $data, $key, $binary = false ) { + return _hash_hmac( $algo, $data, $key, $binary ); } endif; @@ -254,15 +256,15 @@ endif; * @ignore * @since 3.2.0 * - * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. - * @param string $data Data to be hashed. - * @param string $key Secret key to use for generating the hash. - * @param bool $raw_output Optional. Whether to output raw binary data (true), - * or lowercase hexits (false). Default false. - * @return string|false The hash in output determined by `$raw_output`. False if `$algo` - * is unknown or invalid. + * @param string $algo Hash algorithm. Accepts 'md5' or 'sha1'. + * @param string $data Data to be hashed. + * @param string $key Secret key to use for generating the hash. + * @param bool $binary Optional. Whether to output raw binary data (true), + * or lowercase hexits (false). Default false. + * @return string|false The hash in output determined by `$binary`. + * False if `$algo` is unknown or invalid. */ -function _hash_hmac( $algo, $data, $key, $raw_output = false ) { +function _hash_hmac( $algo, $data, $key, $binary = false ) { $packs = array( 'md5' => 'H32', 'sha1' => 'H40', @@ -285,15 +287,16 @@ function _hash_hmac( $algo, $data, $key, $raw_output = false ) { $hmac = $algo( $opad . pack( $pack, $algo( $ipad . $data ) ) ); - if ( $raw_output ) { + if ( $binary ) { return pack( $pack, $hmac ); } + return $hmac; } if ( ! function_exists( 'hash_equals' ) ) : /** - * Timing attack safe string comparison + * Timing attack safe string comparison. * * Compares two strings using the same time whether they're equal or not. * @@ -308,20 +311,22 @@ if ( ! function_exists( 'hash_equals' ) ) : * * @since 3.9.2 * - * @param string $a Expected string. - * @param string $b Actual, user supplied, string. + * @param string $known_string Expected string. + * @param string $user_string Actual, user supplied, string. * @return bool Whether strings are equal. */ - function hash_equals( $a, $b ) { - $a_length = strlen( $a ); - if ( strlen( $b ) !== $a_length ) { + function hash_equals( $known_string, $user_string ) { + $known_string_length = strlen( $known_string ); + + if ( strlen( $user_string ) !== $known_string_length ) { return false; } + $result = 0; // Do not attempt to "optimize" this. - for ( $i = 0; $i < $a_length; $i++ ) { - $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] ); + for ( $i = 0; $i < $known_string_length; $i++ ) { + $result |= ord( $known_string[ $i ] ) ^ ord( $user_string[ $i ] ); } return 0 === $result; @@ -346,14 +351,14 @@ if ( ! function_exists( 'is_countable' ) ) { * * @since 4.9.6 * - * @param mixed $var The value to check. - * @return bool True if `$var` is countable, false otherwise. + * @param mixed $value The value to check. + * @return bool True if `$value` is countable, false otherwise. */ - function is_countable( $var ) { - return ( is_array( $var ) - || $var instanceof Countable - || $var instanceof SimpleXMLElement - || $var instanceof ResourceBundle + function is_countable( $value ) { + return ( is_array( $value ) + || $value instanceof Countable + || $value instanceof SimpleXMLElement + || $value instanceof ResourceBundle ); } } @@ -367,11 +372,11 @@ if ( ! function_exists( 'is_iterable' ) ) { * * @since 4.9.6 * - * @param mixed $var The value to check. - * @return bool True if `$var` is iterable, false otherwise. + * @param mixed $value The value to check. + * @return bool True if `$value` is iterable, false otherwise. */ - function is_iterable( $var ) { - return ( is_array( $var ) || $var instanceof Traversable ); + function is_iterable( $value ) { + return ( is_array( $value ) || $value instanceof Traversable ); } } @@ -384,12 +389,12 @@ if ( ! function_exists( 'array_key_first' ) ) { * * @since 5.9.0 * - * @param array $arr An array. + * @param array $array An array. * @return string|int|null The first key of array if the array * is not empty; `null` otherwise. */ - function array_key_first( array $arr ) { - foreach ( $arr as $key => $value ) { + function array_key_first( array $array ) { + foreach ( $array as $key => $value ) { return $key; } } @@ -404,16 +409,18 @@ if ( ! function_exists( 'array_key_last' ) ) { * * @since 5.9.0 * - * @param array $arr An array. + * @param array $array An array. * @return string|int|null The last key of array if the array *. is not empty; `null` otherwise. */ - function array_key_last( array $arr ) { - if ( empty( $arr ) ) { + function array_key_last( array $array ) { + if ( empty( $array ) ) { return null; } - end( $arr ); - return key( $arr ); + + end( $array ); + + return key( $array ); } } @@ -452,6 +459,7 @@ if ( ! function_exists( 'str_starts_with' ) ) { if ( '' === $needle ) { return true; } + return 0 === strpos( $haystack, $needle ); } } @@ -473,7 +481,9 @@ if ( ! function_exists( 'str_ends_with' ) ) { if ( '' === $haystack && '' !== $needle ) { return false; } + $len = strlen( $needle ); + return 0 === substr_compare( $haystack, $needle, -$len, $len ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 79dea68231..5e7a201144 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53364'; +$wp_version = '6.1-alpha-53365'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.