Title: rest_sanitize_boolean
Published: December 7, 2016
Last modified: August 20, 2026

---

# rest_sanitize_boolean( bool|string|int $value ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#changelog)

Changes a boolean-like value into the proper boolean value.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#parameters)󠁿

 `$value`bool|string|intrequired

The value being evaluated.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#return)󠁿

 bool Returns the proper associated boolean value.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#source)󠁿

    ```php
    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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api.php#L1535)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api.php#L1535-L1546)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#related)󠁿

| Used by | Description | 
| [rest_sanitize_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_sanitize_value_from_schema/)`wp-includes/rest-api.php` |

Sanitize a value based on a schema.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/rest_sanitize_boolean/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Frest_sanitize_boolean%2F)
before being able to contribute a note or feedback.