rest_stabilize_value() WordPress Function

The rest_stabilize_value() function is used to stabilize a value returned from the WordPress REST API. This is useful for values that may change over time, such as the current post ID.

rest_stabilize_value( mixed $value ) #

Stabilizes a value following JSON Schema semantics.


Description

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


Top ↑

Parameters

$value

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


Top ↑

Return

(mixed) The stabilized value.


Top ↑

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
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More