Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/wp-includes/abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ function wp_register_core_abilities(): void {
'db_server_info' => array(
'type' => 'string',
'description' => __( 'The database server vendor and version string reported by the driver.' ),
'examples' => array( '8.0.34', '10.11.6-MariaDB' ),
),
'wp_version' => array(
'type' => 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ public function get_item_permissions_check( $request ) {
return current_user_can( 'read' );
}

/**
* Normalizes schema empty object defaults.
*
* Converts empty array defaults to objects when the schema type is 'object'
* to ensure proper JSON serialization as {} instead of [].
*
* @since 6.9.0
*
* @param array<string, mixed> $schema The schema array.
* @return array<string, mixed> The normalized schema.
*/
private function normalize_schema_empty_object_defaults( array $schema ): array {
if ( isset( $schema['type'] ) && 'object' === $schema['type'] && isset( $schema['default'] ) ) {
$default = $schema['default'];
if ( is_array( $default ) && empty( $default ) ) {
$schema['default'] = (object) $default;
}
}
return $schema;
}

/**
* Prepares an ability for response.
*
Expand All @@ -209,8 +230,8 @@ public function prepare_item_for_response( $ability, $request ) {
'label' => $ability->get_label(),
'description' => $ability->get_description(),
'category' => $ability->get_category(),
'input_schema' => $ability->get_input_schema(),
'output_schema' => $ability->get_output_schema(),
'input_schema' => $this->normalize_schema_empty_object_defaults( $ability->get_input_schema() ),
'output_schema' => $this->normalize_schema_empty_object_defaults( $ability->get_output_schema() ),
'meta' => $ability->get_meta(),
);

Expand Down
Loading