wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
_wp_json_schema_matches_type is private and should not be used in themes or plugins directly.
_wp_json_schema_matches_type › WordPress Function
Seit7.2.0
Veraltetn/v
› _wp_json_schema_matches_type ( $value, $schema, $type )
| Zugriff: |
|
| Parameter: (3) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Determines whether a value matches a JSON Schema through a given type.
Combining schemas must have a matching branch that allows the requested type. Finding the type in one branch and validating the value against another branch is not sufficient.Quellcode
function _wp_json_schema_matches_type( $value, array $schema, string $type ): bool {
if ( isset( $schema['type'] ) && ! in_array( $type, (array) $schema['type'], true ) ) {
return false;
}
foreach ( array( 'anyOf', 'oneOf' ) as $keyword ) {
if ( ! isset( $schema[ $keyword ] ) ) {
continue;
}
foreach ( $schema[ $keyword ] as $sub_schema ) {
if ( ! is_array( $sub_schema ) ) {
continue;
}
// Match rest_find_any_matching_schema(), which applies the parent type to untyped branches.
if ( ! isset( $sub_schema['type'] ) && isset( $schema['type'] ) ) {
$sub_schema['type'] = $schema['type'];
}
if ( _wp_json_schema_matches_type( $value, $sub_schema, $type ) ) {
continue 2;
}
}
return false;
}
if ( ! isset( $schema['type'] ) && ! isset( $schema['anyOf'] ) && ! isset( $schema['oneOf'] ) ) {
return false;
}
// Explicit and inferred types must both validate through the requested type only.
$schema['type'] = $type;
return ! is_wp_error( rest_validate_value_from_schema( $value, $schema ) );
}