Skip to:
Content

BuddyPress.org

Ticket #6013: 6013.wp_parse_str.patch

File 6013.wp_parse_str.patch, 1.6 KB (added by r-a-y, 12 years ago)
  • src/bp-core/bp-core-filters.php

     
    6969add_filter( 'comments_open', 'bp_comments_open', 10, 2 );
    7070
    7171/**
     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 */
     79function 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}
     88add_filter( 'wp_parse_str', 'bp_core_parse_array_values_to_boolean' );
     89
     90/**
    7291 * Prevent specific pages (eg 'Activate') from showing on page listings.
    7392 *
    7493 * @uses bp_is_active() checks if a BuddyPress component is active.
  • tests/phpunit/testcases/core/functions.php

     
    614614                        date_default_timezone_set( $tz_backup );
    615615                }
    616616        }
     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        }
    617628}