Commit f63e19cf07 for wordpress.org
commit f63e19cf07e31c220e88b32a6ed4d8d2990cb730
Author: gziolo <gziolo@git.wordpress.org>
Date: Mon Oct 12 14:40:55 2026 +0000
JSON schema: Send empty object defaults as `{}` for union types
`wp_prepare_json_schema_for_client()` already changes an empty array `default` to an object when the type is `object`. Now it also does this when the type is a list that includes `object` but not `array`, like `array( 'object', 'null' )`. If `array` is allowed, the default stays `[]`.
Developed in https://github.com/WordPress/wordpress-develop/pull/14068.
Follow-up to [62591].
Props sukhendu2002.
See #66267.
Built from https://develop.svn.wordpress.org/trunk@64315
git-svn-id: http://core.svn.wordpress.org/trunk@63465 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/json-schema.php b/wp-includes/json-schema.php
index 782ad9714f..bec3656f66 100644
--- a/wp-includes/json-schema.php
+++ b/wp-includes/json-schema.php
@@ -104,11 +104,9 @@ function wp_prepare_json_schema_for_client( array $schema, string $schema_profil
* @return array<string, mixed> The prepared schema.
*/
function _wp_prepare_json_schema_for_client_with_allowed_keywords( array $schema, array $allowed_keywords ): array {
- if ( isset( $schema['type'] ) && 'object' === $schema['type'] && isset( $schema['default'] ) ) {
- $default = $schema['default'];
- if ( is_array( $default ) && empty( $default ) ) {
- $schema['default'] = (object) $default;
- }
+ $types = isset( $schema['type'] ) ? (array) $schema['type'] : array();
+ if ( isset( $schema['default'] ) && array() === $schema['default'] && in_array( 'object', $types, true ) && ! in_array( 'array', $types, true ) ) {
+ $schema['default'] = new stdClass();
}
$schema = array_intersect_key( $schema, $allowed_keywords );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index d0c517d8e8..9f9d816504 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-64314';
+$wp_version = '7.2-alpha-64315';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.