wpseek.com
WordPress开发者和主题制作者的搜索引擎
_wp_json_schema_matches_type is private and should not be used in themes or plugins directly.
_wp_json_schema_matches_type › WordPress Function
Since7.2.0
已弃用n/a
› _wp_json_schema_matches_type ( $value, $schema, $type )
| 访问: |
|
| 参数: (3) |
|
| 返回: |
|
| 定义在: |
|
| 文档: |
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.源码
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 ) );
}