WP_REST_Abilities_V1_List_Controller::normalize_schema_empty_object_defaults( $schema ): array<string,

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Normalizes schema empty object defaults.

Description

Converts empty array defaults to objects when the schema type is ‘object’ to ensure proper JSON serialization as {} instead of [].

Parameters

mixed> $schema The schema array.

Return

array<string, mixed> The normalized schema.

Source

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;
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.