Validator
in package
Validates and sanitizes values based on a schema.
Table of Contents
- validate() : mixed
- Strict validation & sanitization implementation.
- validate_schema_array() : mixed
- Strict validation & sanitization implementation.
- get_type_error() : WP_Error
- Returns a WP_Error for a type mismatch.
- validate_and_sanitize_any_of() : mixed|WP_Error
- Mirrors rest_find_any_matching_schema().
- validate_and_sanitize_one_of() : mixed|WP_Error
- Mirrors rest_find_one_matching_schema().
- validate_and_sanitize_value_from_schema() : mixed|WP_Error
- Mirrors rest_validate_value_from_schema() and rest_sanitize_value_from_schema().
Methods
validate()
Strict validation & sanitization implementation.
public
validate(Schema $schema, mixed $value[, string $param_name = 'value' ]) : mixed
It only coerces int to float (e.g. 5 to 5.0).
Parameters
- $schema : Schema
-
The schema to validate against.
- $value : mixed
-
The value to validate.
- $param_name : string = 'value'
-
The parameter name.
Return values
mixed —validate_schema_array()
Strict validation & sanitization implementation.
public
validate_schema_array(array<string|int, mixed> $schema, mixed $value[, string $param_name = 'value' ]) : mixed
It only coerces int to float (e.g. 5 to 5.0).
Parameters
- $schema : array<string|int, mixed>
-
The array must follow the format, which is returned from Schema::toArray().
- $value : mixed
-
The value to validate.
- $param_name : string = 'value'
-
The parameter name.
Tags
Return values
mixed —get_type_error()
Returns a WP_Error for a type mismatch.
private
get_type_error(string $param, string|array<string|int, string> $type) : WP_Error
Parameters
- $param : string
-
The parameter name.
- $type : string|array<string|int, string>
-
The expected type.
Return values
WP_Error —validate_and_sanitize_any_of()
Mirrors rest_find_any_matching_schema().
private
validate_and_sanitize_any_of(mixed $value, array<string|int, mixed> $any_of_schema, string $param_name) : mixed|WP_Error
Parameters
- $value : mixed
-
The value to validate.
- $any_of_schema : array<string|int, mixed>
-
The schema to validate against.
- $param_name : string
-
The parameter name.
Return values
mixed|WP_Error —validate_and_sanitize_one_of()
Mirrors rest_find_one_matching_schema().
private
validate_and_sanitize_one_of(mixed $value, array<string|int, mixed> $one_of_schema, string $param_name) : mixed|WP_Error
Parameters
- $value : mixed
-
The value to validate.
- $one_of_schema : array<string|int, mixed>
-
The schema to validate against.
- $param_name : string
-
The parameter name.
Return values
mixed|WP_Error —validate_and_sanitize_value_from_schema()
Mirrors rest_validate_value_from_schema() and rest_sanitize_value_from_schema().
private
validate_and_sanitize_value_from_schema(mixed $value, array<string|int, mixed> $schema, string $param_name) : mixed|WP_Error
Parameters
- $value : mixed
-
The value to validate.
- $schema : array<string|int, mixed>
-
The schema to validate against.
- $param_name : string
-
The parameter name.