rest_sanitize_object( mixed $maybe_object ): array

Converts an object-like value to an array.


Parameters

$maybe_object mixed Required
The value being evaluated.

Top ↑

Return

array Returns the object extracted from the value as an associative array.


Top ↑

Source

File: wp-includes/rest-api.php. View all references

function rest_sanitize_object( $maybe_object ) {
	if ( '' === $maybe_object ) {
		return array();
	}

	if ( $maybe_object instanceof stdClass ) {
		return (array) $maybe_object;
	}

	if ( $maybe_object instanceof JsonSerializable ) {
		$maybe_object = $maybe_object->jsonSerialize();
	}

	if ( ! is_array( $maybe_object ) ) {
		return array();
	}

	return $maybe_object;
}


Top ↑

Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes

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