rest_stabilize_value( mixed $value )

Stabilizes a value following JSON Schema semantics.


Description Description

For lists, order is preserved. For objects, properties are reordered alphabetically.


Top ↑

Parameters Parameters

$value

(mixed) (Required) The value to stabilize. Must already be sanitized. Objects should have been converted to arrays.


Top ↑

Return Return

(mixed) The stabilized value.


Top ↑

Source Source

File: wp-includes/rest-api.php

function rest_stabilize_value( $value ) {
	if ( is_scalar( $value ) || is_null( $value ) ) {
		return $value;
	}

	if ( is_object( $value ) ) {
		_doing_it_wrong( __FUNCTION__, __( 'Cannot stabilize objects. Convert the object to an array first.' ), '5.5.0' );

		return $value;
	}

	ksort( $value );

	foreach ( $value as $k => $v ) {
		$value[ $k ] = rest_stabilize_value( $v );
	}

	return $value;
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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