diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index dce925a677..8ca5ca17de 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4740,7 +4740,9 @@ function reset_mbstring_encoding() { } /** - * Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ). + * Filter/validate a variable as a boolean. + * + * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`. * * @since 4.0.0 * @@ -4752,7 +4754,7 @@ function wp_validate_boolean( $var ) { return $var; } - if ( 'false' === $var ) { + if ( is_string( $var ) && 'false' === strtolower( $var ) ) { return false; } diff --git a/tests/phpunit/tests/functions/WpValidateBoolean.php b/tests/phpunit/tests/functions/WpValidateBoolean.php index 812563757e..38a731e31c 100644 --- a/tests/phpunit/tests/functions/WpValidateBoolean.php +++ b/tests/phpunit/tests/functions/WpValidateBoolean.php @@ -56,4 +56,20 @@ class Tests_Functions_WpValidateBoolean extends WP_UnitTestCase { // Differs from (bool) conversion. $this->assertFalse( wp_validate_boolean( 'false' ) ); } + + /** + * @ticket 30238 + */ + public function test_string_false_uppercase() { + // Differs from (bool) conversion. + $this->assertFalse( wp_validate_boolean( 'FALSE' ) ); + } + + /** + * @ticket 30238 + */ + public function test_string_false_mixedcase() { + // Differs from (bool) conversion. + $this->assertFalse( wp_validate_boolean( 'FaLsE' ) ); + } }