rest_sanitize_boolean

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

WordPress Version: 5.6

/**
 * Changes a boolean-like value into the proper boolean value.
 *
 * @since 4.7.0
 *
 * @param bool|string|int $value The value being evaluated.
 * @return bool Returns the proper associated boolean value.
 */
function rest_sanitize_boolean($value)
{
    // String values are translated to `true`; make sure 'false' is false.
    if (is_string($value)) {
        $value = strtolower($value);
        if (in_array($value, array('false', '0'), true)) {
            $value = false;
        }
    }
    // Everything else will map nicely to boolean.
    return (bool) $value;
}

WordPress Version: 4.7

/**
 * Changes a boolean-like value into the proper boolean value.
 *
 * @since 4.7.0
 *
 * @param bool|string|int $value The value being evaluated.
 * @return boolean Returns the proper associated boolean value.
 */
function rest_sanitize_boolean($value)
{
    // String values are translated to `true`; make sure 'false' is false.
    if (is_string($value)) {
        $value = strtolower($value);
        if (in_array($value, array('false', '0'), true)) {
            $value = false;
        }
    }
    // Everything else will map nicely to boolean.
    return (bool) $value;
}