Because PHP can be configured without --filter, it is not 100% safe to use filter_var(). This is problematic for casting "false" to false, as PHP always casts it to true. FILTER_VALIDATE_BOOLEAN fixes this, but it may not be available.

Add a new function, `wp_validate_boolean()`, to replace `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.

Fixes #28170.



git-svn-id: https://develop.svn.wordpress.org/trunk@28542 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-05-22 18:33:34 +00:00
parent 0baa73f2e4
commit d6f1c4f904
2 changed files with 24 additions and 4 deletions

View File

@ -4445,3 +4445,23 @@ function mbstring_binary_safe_encoding( $reset = false ) {
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
/**
* Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN )
*
* @since 4.0.0
*
* @param mixed $var
* @return boolean
*/
function wp_validate_boolean( $var ) {
if ( is_bool( $var ) ) {
return $var;
}
if ( 'false' === $var ) {
return false;
}
return (bool) $var;
}

View File

@ -1272,10 +1272,10 @@ function wp_playlist_shortcode( $attr ) {
$data = array(
'type' => $atts['type'],
// don't pass strings to JSON, will be truthy in JS
'tracklist' => filter_var( $atts['tracklist'], FILTER_VALIDATE_BOOLEAN ),
'tracknumbers' => filter_var( $atts['tracknumbers'], FILTER_VALIDATE_BOOLEAN ),
'images' => filter_var( $atts['images'], FILTER_VALIDATE_BOOLEAN ),
'artists' => filter_var( $atts['artists'], FILTER_VALIDATE_BOOLEAN ),
'tracklist' => wp_validate_boolean( $atts['tracklist'] ),
'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ),
'images' => wp_validate_boolean( $atts['images'] ),
'artists' => wp_validate_boolean( $atts['artists'] ),
);
$tracks = array();