rest_validate_boolean_value_from_schema()WP 5.7.0

Validates a boolean value based on a schema.

No Hooks.

Return

true|WP_Error.

Usage

rest_validate_boolean_value_from_schema( $value, $param );
$value(mixed) (required)
The value to validate.
$param(string) (required)
The parameter name, used in error messages.

Changelog

Since 5.7.0 Introduced.

rest_validate_boolean_value_from_schema() code WP 6.4.3

function rest_validate_boolean_value_from_schema( $value, $param ) {
	if ( ! rest_is_boolean( $value ) ) {
		return new WP_Error(
			'rest_invalid_type',
			/* translators: 1: Parameter, 2: Type name. */
			sprintf( __( '%1$s is not of type %2$s.' ), $param, 'boolean' ),
			array( 'param' => $param )
		);
	}

	return true;
}