rest_sanitize_object()WP 5.5.0

Converts an object-like value to an array.

Хуков нет.

Возвращает

Массив. Returns the object extracted from the value as an associative array.

Использование

rest_sanitize_object( $maybe_object );
$maybe_object(разное) (обязательный)
The value being evaluated.

Список изменений

С версии 5.5.0 Введена.

Код rest_sanitize_object() WP 6.6.2

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