wp_validate_boolean

The timeline below displays how wordpress function wp_validate_boolean has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Filters/validates a variable as a boolean.
 *
 * Alternative to `filter_var( $value, FILTER_VALIDATE_BOOLEAN )`.
 *
 * @since 4.0.0
 *
 * @param mixed $value Boolean value to validate.
 * @return bool Whether the value is validated.
 */
function wp_validate_boolean($value)
{
    if (is_bool($value)) {
        return $value;
    }
    if (is_string($value) && 'false' === strtolower($value)) {
        return false;
    }
    return (bool) $value;
}

WordPress Version: 6.1

/**
 * Filters/validates a variable as a boolean.
 *
 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
 *
 * @since 4.0.0
 *
 * @param mixed $var Boolean value to validate.
 * @return bool Whether the value is validated.
 */
function wp_validate_boolean($var)
{
    if (is_bool($var)) {
        return $var;
    }
    if (is_string($var) && 'false' === strtolower($var)) {
        return false;
    }
    return (bool) $var;
}

WordPress Version: 4.1

/**
 * Filter/validate a variable as a boolean.
 *
 * Alternative to `filter_var( $var, FILTER_VALIDATE_BOOLEAN )`.
 *
 * @since 4.0.0
 *
 * @param mixed $var Boolean value to validate.
 * @return bool Whether the value is validated.
 */
function wp_validate_boolean($var)
{
    if (is_bool($var)) {
        return $var;
    }
    if (is_string($var) && 'false' === strtolower($var)) {
        return false;
    }
    return (bool) $var;
}

WordPress Version: 4.0

/**
 * Alternative to filter_var( $var, FILTER_VALIDATE_BOOLEAN ).
 *
 * @since 4.0.0
 *
 * @param mixed $var Boolean value to validate.
 * @return bool Whether the value is validated.
 */
function wp_validate_boolean($var)
{
    if (is_bool($var)) {
        return $var;
    }
    if ('false' === $var) {
        return false;
    }
    return (bool) $var;
}