WP_REST_Abilities_V1_List_Controller::normalize_schema_empty_object_defaultsprivateWP 6.9.0

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 [].

Method of the class: WP_REST_Abilities_V1_List_Controller{}

No Hooks.

Returns

Array. mixed> The normalized schema.

Usage

// private - for code of main (parent) class only
$result = $this->normalize_schema_empty_object_defaults( $schema ): array;
$schema(array) (required)
.

Changelog

Since 6.9.0 Introduced.

WP_REST_Abilities_V1_List_Controller::normalize_schema_empty_object_defaults() code WP 6.9

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