Ticket #6013: 6013.wp_parse_str.patch
| File 6013.wp_parse_str.patch, 1.6 KB (added by , 12 years ago) |
|---|
-
src/bp-core/bp-core-filters.php
69 69 add_filter( 'comments_open', 'bp_comments_open', 10, 2 ); 70 70 71 71 /** 72 * Fixes parsing of 'true' and 'false' strings into booleans when using wp_parse_str(). 73 * 74 * @since BuddyPress (2.2.0) 75 * 76 * @param array $r The array to check for 'true' / 'false' strings 77 * @return array 78 */ 79 function bp_core_parse_array_values_to_boolean( $r = array() ) { 80 foreach( (array) $r as $key => $value ) { 81 if ( is_string( $value ) && ( 'true' === $value || 'false' === $value ) ) { 82 $r[$key] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); 83 } 84 } 85 86 return $r; 87 } 88 add_filter( 'wp_parse_str', 'bp_core_parse_array_values_to_boolean' ); 89 90 /** 72 91 * Prevent specific pages (eg 'Activate') from showing on page listings. 73 92 * 74 93 * @uses bp_is_active() checks if a BuddyPress component is active. -
tests/phpunit/testcases/core/functions.php
614 614 date_default_timezone_set( $tz_backup ); 615 615 } 616 616 } 617 618 /** 619 * @group wp_parse_str 620 */ 621 public function test_wp_parse_str_strings_as_booleans() { 622 // use a string; wp_parse_str() is used 623 $r = wp_parse_args( 'this_should_be_bool_false=false&this_should_be_bool_true=true', array() ); 624 625 $this->assertFalse( $r['this_should_be_bool_false'] ); 626 $this->assertTrue( $r['this_should_be_bool_true'] ); 627 } 617 628 }