Tweaks wc_clean to ignore non-scalar vars

Also for #10937 @thenbrent
This commit is contained in:
Mike Jolley 2016-06-02 12:52:00 +01:00
parent d9db29a035
commit b2f9c60a08
1 changed files with 7 additions and 2 deletions

View File

@ -254,12 +254,17 @@ function wc_format_localized_decimal( $value ) {
}
/**
* Clean variables using sanitize_text_field.
* Clean variables using sanitize_text_field. Arrays are cleaned recursively.
* Non-scalar values are ignored.
* @param string|array $var
* @return string|array
*/
function wc_clean( $var ) {
return is_array( $var ) ? array_map( 'wc_clean', $var ) : sanitize_text_field( $var );
if ( is_array( $var ) ) {
return array_map( 'wc_clean', $var );
} else {
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
}
}
/**