On this page
rest_find_any_matching_schema( mixed $value, array $args, string $param ): array|WP_Error
Finds the matching schema among the “anyOf” schemas.
Parameters
$valuemixed Required-
The value to validate.
$argsarray Required-
The schema array to use.
$paramstring Required-
The parameter name, used in error messages.
Return
array|WP_Error The matching schema or WP_Error instance if all schemas do not match.
Source
File: wp-includes/rest-api.php. View all references
function rest_find_any_matching_schema( $value, $args, $param ) {
$errors = array();
foreach ( $args['anyOf'] as $index => $schema ) {
if ( ! isset( $schema['type'] ) && isset( $args['type'] ) ) {
$schema['type'] = $args['type'];
}
$is_valid = rest_validate_value_from_schema( $value, $schema, $param );
if ( ! is_wp_error( $is_valid ) ) {
return $schema;
}
$errors[] = array(
'error_object' => $is_valid,
'schema' => $schema,
'index' => $index,
);
}
return rest_get_combining_operation_error( $value, $param, $errors );
}
Related
Uses
| Uses | Description |
|---|---|
| rest_get_combining_operation_error() wp-includes/rest-api.php | Gets the error of combining operation. |
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| rest_filter_response_by_context() wp-includes/rest-api.php | Filters the response to remove any fields not available in the given context. |
| rest_sanitize_value_from_schema() wp-includes/rest-api.php | Sanitize a value based on a schema. |
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
Changelog
| Version | Description |
|---|---|
| 5.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_find_any_matching_schema