diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index dce925a..8ca5ca1 100644
|
|
function reset_mbstring_encoding() { |
4740 | 4740 | } |
4741 | 4741 | |
4742 | 4742 | /** |
4743 | | * Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ). |
| 4743 | * Filter/validate a variable as a boolean. |
| 4744 | * |
| 4745 | * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`. |
4744 | 4746 | * |
4745 | 4747 | * @since 4.0.0 |
4746 | 4748 | * |
… |
… |
function wp_validate_boolean( $var ) { |
4752 | 4754 | return $var; |
4753 | 4755 | } |
4754 | 4756 | |
4755 | | if ( 'false' === $var ) { |
| 4757 | if ( is_string( $var ) && 'false' === strtolower( $var ) ) { |
4756 | 4758 | return false; |
4757 | 4759 | } |
4758 | 4760 | |
diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
index c52623e..2a3eb6d 100644
|
|
class Tests_Functions extends WP_UnitTestCase { |
571 | 571 | $json = wp_json_encode( $data, 0, 1 ); |
572 | 572 | $this->assertFalse( $json ); |
573 | 573 | } |
| 574 | |
| 575 | /** |
| 576 | * @ticket 30238 |
| 577 | */ |
| 578 | function test_wp_validate_boolean() { |
| 579 | // Cases where wp_validate_boolean() equals (bool) conversion: |
| 580 | $this->assertTrue( wp_validate_boolean( true ) ); |
| 581 | $this->assertTrue( wp_validate_boolean( 1 ) ); |
| 582 | $this->assertTrue( wp_validate_boolean( 'true' ) ); |
| 583 | $this->assertTrue( wp_validate_boolean( 'TRUE' ) ); |
| 584 | $this->assertTrue( wp_validate_boolean( 'foobar' ) ); |
| 585 | $this->assertFalse( wp_validate_boolean( false ) ); |
| 586 | $this->assertFalse( wp_validate_boolean( 0 ) ); |
| 587 | $this->assertFalse( wp_validate_boolean( 0.0 ) ); |
| 588 | $this->assertFalse( wp_validate_boolean( '' ) ); |
| 589 | $this->assertFalse( wp_validate_boolean( '0' ) ); |
| 590 | $this->assertFalse( wp_validate_boolean( array() ) ); |
| 591 | $this->assertFalse( wp_validate_boolean( null ) ); |
| 592 | |
| 593 | // Cases where wp_validate_boolean() differs from (bool) conversion: |
| 594 | $this->assertFalse( wp_validate_boolean( 'false' ) ); |
| 595 | $this->assertFalse( wp_validate_boolean( 'FALSE' ) ); |
| 596 | $this->assertFalse( wp_validate_boolean( 'FalsE' ) ); |
| 597 | } |
574 | 598 | } |