The WordPress coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. development team builds WordPress! Follow this site for general updates, status reports, and the occasional code debate. There’s lots of ways to contribute:
Found a bugbugA bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority.?Create a ticket in the bug tracker.
JSON Schema preparation for client compatibility in WordPress 7.1
WordPress 7.1 introduces a shared JSONJSONJSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. Schema preparation layer for schemas exposed to REST clients, frontend applications, and AI tools.
WordPress accepts several internal schema conventions that are useful during server-side validation but are not portable JSON Schema draft-04. Passing these schemas directly to external validators could cause validation errors or expose PHPPHPThe web scripting language in which WordPress is primarily architected. WordPress requires PHP 7.4 or higher callbacks and other server-only implementation details.
The wp_prepare_json_schema_for_client() function
The new wp_prepare_json_schema_for_client() function converts a WordPress schema into a portable, client-facing representation before it is exposed to REST clients, frontend applications, AI tools, or other external consumers.
Most developers do not need to take action. CoreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. now applies this preparation automatically to:
Abilities APIAPIAn API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways. schemas exposed through REST responses.
Ability input schemas converted into AI Client function declarations.
This keeps the schemas used by clients (REST clients, JavaScriptJavaScriptJavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user’s browser.
https://www.javascript.com applications, and AI tools) consistent. See ticketticketCreated for both bug reports and feature development on the bug tracker.#64955 and changeset [62591].
Compatibility guidance
This change is primarily automatic. Existing ability registration and execution code does not need to call the new function.
Call wp_prepare_json_schema_for_client() directly when a pluginPluginA plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party. exposes a WordPress-style schema outside the server-side PHP validation boundary, for example through:
a custom REST endpoint;
a JavaScript configuration object;
an MCP tool declaration;
an AI function declaration; or
another external schema consumer.
Do not replace the schema stored by an ability with the prepared version. Keep the canonical WordPress schema for server-side use and prepare a copy only when sending it to a client.
Choosing a schema profile
This new function accepts a schema and an optional schema profile:
/**
* Prepares a JSON Schema for clients.
*
* @param array<string, mixed> $schema The schema array.
* @param string $schema_profile Optional. Name of the schema
* profile whose keywords should be
* preserved. Default 'draft-04'.
* @return array<string, mixed> The prepared schema.
*/
wp_prepare_json_schema_for_client(
array $schema,
string $schema_profile = 'draft-04'
): array
WordPress provides two schema profiles out of the box:
draft-04is the default. Use it when publishing a standalone schema to general-purpose clients, including Ability metadata, frontend validators, MCP integrations, and AI tooling. It preserves the broader JSON Schema Draft 4 vocabulary, including composition and reference keywords such as $ref, definitions, allOf, not, dependencies, and additionalItems.
rest-api uses the narrower keyword set supported by WordPress REST APIREST APIThe REST API is an acronym for the RESTful Application Program Interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. It is how the front end of an application (think “phone app” or “website”) can communicate with the data store (think “database” or “file system”)
https://developer.wordpress.org/rest-api/ route schemas. Use it when preparing a schema that must follow the same conventions as a REST route’s argument or response schema.
// General client-facing or Ability schema.
$prepared_schema = wp_prepare_json_schema_for_client( $schema );
// Schema intended to match WordPress REST API conventions.
$prepared_rest_schema = wp_prepare_json_schema_for_client(
$schema,
'rest-api'
);
Both profiles produce JSON Schema Draft 4 output. The difference is the set of keywords retained in the prepared schema.
What is JSON Schema Draft 4?
“Draft 4” refers to the fourth published draft of the JSON Schema specification, which defines a JSON-based contract for describing and validating JSON data. See the JSON Schema Draft 4 core specification for its terminology and behaviour.
Schema transformations
Preparation is recursive and applies to nested object properties, array items, composition keywords, definitions, dependencies, and other subschemas.
Required properties use Draft 4 syntax
WordPress schemas may mark individual properties as required:
The prepared schema moves those property names into the containing object’s Draft 4 required array:
'required' => array( 'title' ),
The property-level boolean is then removed.
If the object already has a valid required array, that array takes precedence over property-level boolean values. A property-level required => false is removed without creating an empty required array.
A boolean required value on a scalar schema is also removed because it has no Draft 4 equivalent.
This preparation only affects schemas sent to clients. It does not change the server-side behaviour of rest_validate_value_from_schema() or WP_Ability::validate_input().
PHP callbacks and other WordPress-specific keywords cannot be represented meaningfully in JSON. The preparation process removes unsupported keywords, including:
sanitize_callback
validate_callback
arg_options
These keywords are removed recursively, including when they appear inside:
properties
patternProperties
definitions
dependencies
items
additionalItems
additionalProperties
anyOf
oneOf
allOf
not
The callbacks remain available in the original server-side schema. They are removed only from its client-facing representation.
Ability authors should also note that validate_callback and sanitize_callback are not executed by the Abilities API’s runtime validation. Custom ability validation should use the wp_ability_validate_input and wp_ability_validate_outputfilters introduced in WordPress 7.1.
Empty object defaults are represented as objects
In PHP, an empty array serializes to [], even when its schema declares an object:
For client-facing schemas, the empty default is prepared so that JSON serialization produces an object:
{
"type": "object",
"default": {}
}
This prevents client validators from rejecting the default because its serialized type does not match the declared object type.
Allowed keywords filterFilterFilters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.
wp_prepare_json_schema_for_client() uses wp_get_json_schema_allowed_keywords() to decide which keywords to preserve.
The broader draft-04 profile can preserve composition and documentation keywords such as:
$ref
definitions
allOf
not
dependencies
additionalItems
Preserving a keyword means that it may be included in the client-facing schema. It does not mean that WordPress validates or sanitizes values against that keyword on the server.
This prevents WordPress-only schema keywords and nonportable required conventions from being passed directly into AI function declarations.
The helper prepares a portable Draft 4 schema; it is not a provider-specific compiler. Individual AI providers may support a smaller schema vocabulary or impose additional requirements. Provider-specific adaptation may therefore still occur elsewhere in the integration.
Follow-up
Provider-specific adaptation is tracked in WordPress/php-ai-client#256: each provider should be able to override the input schema for its own API requirements, which differ across providers and evolve over time.
Related ticket
#64955 — Add schema compiler for AI tool calling compatibility