WordPress开发者和主题制作者的搜索引擎



wp_validate_boolean ›

Since4.0.0
已弃用n/a
wp_validate_boolean ( $var )
参数:
  • (mixed) $var Boolean value to validate.
    Required: Yes
返回:
  • (bool) Whether the value is validated.
定义在:
文档:

Filter/validate a variable as a boolean.

Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).



源码

function wp_validate_boolean( $var ) {
	if ( is_bool( $var ) ) {
		return $var;
	}

	if ( is_string( $var ) && 'false' === strtolower( $var ) ) {
		return false;
	}

	return (bool) $var;
}