wp_get_json_schema_allowed_keywords( string $schema_profile = 'rest-api' ): string[]
- Since
- 7.1.0
- Source
wp-includes/json-schema.php:32
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.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
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'
Return value
string[]- Allowed JSON Schema keywords.
Performance profile
How much work a call to wp_get_json_schema_allowed_keywords() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 22–23
- Plugin surface
- 1 hook
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 23.
Third-party callbacks on 'wp_json_schema_allowed_keywords' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_json_schema_allowed_keywords() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 22–23 | rest_get_allowed_schema_keywords(), array_merge(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 23 instructions, 22–23 executed per call, 1 branch. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_get_json_schema_allowed_keywords() runs, in this order:
- apply_filters( wp_json_schema_allowed_keywords )filterline 68 (+36 into the body)
Filters the JSON Schema keywords allowed for a given schema profile.
Uses · 2
- rest_get_allowed_schema_keywords()Get all valid JSON schema properties.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 2
- WP_REST_Server::get_data_for_route()Retrieves publicly-visible data for the route.
- wp_prepare_json_schema_for_client()Prepares a JSON Schema for clients.
Source code
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 );}Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/json-schema.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.