Gets the JSON Schema keywords allowed for a given schema profile.
Description
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.
Parameters
$schema_profilestringoptional- Name of the schema profile to get keywords for.
Accepts'rest-api'or'draft-04'. Any other value falls back to the'rest-api'profile. Default'rest-api'.Default:
'rest-api'
Source
function wp_get_json_schema_allowed_keywords( string $schema_profile = 'rest-api' ): array {
$rest_keywords = rest_get_allowed_schema_keywords();
$keywords_by_profile = array(
'rest-api' => $rest_keywords,
'draft-04' => array_merge(
array(
'$schema',
'id',
'$ref',
),
$rest_keywords,
array(
'required',
'allOf',
'not',
'definitions',
'dependencies',
'additionalItems',
)
),
);
$allowed_keywords = $keywords_by_profile[ $schema_profile ] ?? $rest_keywords;
/**
* Filters the JSON Schema keywords allowed for a given schema profile.
*
* Use this to decide which keywords may be exposed to clients for a profile.
* It does not make WordPress validate or sanitize values against the keyword.
*
* @since 7.1.0
*
* @param string[] $allowed_keywords Allowed JSON Schema keywords.
* @param string $schema_profile The schema profile the keywords are for.
*/
return apply_filters( 'wp_json_schema_allowed_keywords', $allowed_keywords, $schema_profile );
}
Hooks
- apply_filters( ‘wp_json_schema_allowed_keywords’,
string[] $allowed_keywords ,string $schema_profile ) Filters the JSON Schema keywords allowed for a given schema profile.
Changelog
| Version | Description |
|---|---|
| 7.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.