| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Source view] [Print] [Project Stats]
JSON Schema API: shared functions for working with JSON Schema.
| File Size: | 369 lines (13 kb) |
| Included or required: | 0 times |
| Referenced: | 0 times |
| Includes or requires: | 0 files |
| wp_get_json_schema_allowed_keywords( string $schema_profile = 'rest-api' ) X-Ref |
| Gets the JSON Schema keywords allowed for a given schema profile. Use this when preparing a schema that will be consumed outside of WordPress's server-side validation, such as by REST clients, frontend code, or AI providers. The 'rest-api' profile returns the subset of JSON Schema draft-04 keywords that the REST API has historically exposed. The 'draft-04' profile preserves the larger draft-04 vocabulary used by clients that can consume standalone schemas. Allowing a keyword to be exposed does not make WordPress validate or sanitize values against it. param: string $schema_profile Optional. Name of the schema profile to get keywords for. return: string[] Allowed JSON Schema keywords. |
| wp_prepare_json_schema_for_client( array $schema, string $schema_profile = 'draft-04' ) X-Ref |
| Prepares a JSON Schema for clients. Converts WordPress-specific schema conventions and removes unsupported keywords so clients can interpret the schema using the selected profile. Applies the same preparation to nested schemas. Existing default values are normalized according to their schemas so empty objects encode as `{}` rather than `[]`, including within nested default values. param: array<string, mixed> $schema The schema array. param: string $schema_profile Optional. Name of the schema profile return: array<string, mixed> The prepared schema. |
| _wp_prepare_json_schema_for_client_with_allowed_keywords( array $schema, array $allowed_keywords ) X-Ref |
| Prepares a JSON Schema for clients using a given keyword lookup. Normalizes schema conventions and default values throughout nested schemas while retaining only the allowed keywords. param: array<string, mixed> $schema The schema array. param: array<string, true> $allowed_keywords Lookup map of allowed JSON Schema keywords. return: array<string, mixed> The prepared schema. |
| wp_prepare_json_value_for_client( $value, array $schema ) X-Ref |
| Prepares a value for JSON encoding according to its schema. Preserves the distinction between JSON objects and arrays by converting empty PHP arrays to objects where the schema identifies them as objects. Nested properties and items are prepared according to their schemas. Empty arrays remain arrays when a matching schema allows them. Prepares the representation of existing values without inserting defaults or performing full JSON Schema validation. param: mixed $value The value to prepare. param: array<string, mixed> $schema The schema describing the value. return: mixed The value prepared for JSON encoding. |
| _wp_json_schema_matches_type( $value, array $schema, string $type ) X-Ref |
| 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. param: mixed $value The value to validate. param: array<string, mixed> $schema The schema to inspect. param: string $type The type to match. return: bool Whether the value matches the schema through the requested type. |
| Generated : Sat Oct 24 08:20:34 2026 | Cross-referenced by PHPXref |