# rest_validate_array_value_from_schema()

URL: https://chugunov.pro/api-wordpress/functions/rest_validate_array_value_from_schema/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.7.0.

## Сигнатура

```php
rest_validate_array_value_from_schema( mixed $value, array $args, string $param ): true|WP_Error
```

## Описание

Проверяет значение-массив на соответствие схеме.

## Параметры

- `$value` `mixed` — обязательный. Значение для проверки.
- `$args` `array` — обязательный. Массив схемы, используемый для проверки.
- `$param` `string` — обязательный. Имя параметра, используемое в сообщениях об ошибках.

## Возвращаемое значение

`true|WP_Error`

## Исходный код

Файл: `wp-includes/rest-api.php:2481`

```php
function rest_validate_array_value_from_schema( $value, $args, $param ) {
	if ( ! rest_is_array( $value ) ) {
		return new WP_Error(
			'rest_invalid_type',
			/* translators: 1: Parameter, 2: Type name. */
			sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ),
			array( 'param' => $param )
		);
	}

	$value = rest_sanitize_array( $value );

	if ( isset( $args['items'] ) ) {
		foreach ( $value as $index => $v ) {
			$is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' );
			if ( is_wp_error( $is_valid ) ) {
				return $is_valid;
			}
		}
	}

	if ( isset( $args['minItems'] ) && count( $value ) < $args['minItems'] ) {
		return new WP_Error(
			'rest_too_few_items',
			sprintf(
				/* translators: 1: Parameter, 2: Number. */
				_n(
					'%1$s must contain at least %2$s item.',
					'%1$s must contain at least %2$s items.',
					$args['minItems']
				),
				$param,
				number_format_i18n( $args['minItems'] )
			)
		);
	}

	if ( isset( $args['maxItems'] ) && count( $value ) > $args['maxItems'] ) {
		return new WP_Error(
			'rest_too_many_items',
			sprintf(
				/* translators: 1: Parameter, 2: Number. */
				_n(
					'%1$s must contain at most %2$s item.',
					'%1$s must contain at most %2$s items.',
					$args['maxItems']
				),
				$param,
				number_format_i18n( $args['maxItems'] )
			)
		);
	}

	if ( ! empty( $args['uniqueItems'] ) && ! rest_validate_array_contains_unique_items( $value ) ) {
		/* translators: %s: Parameter. */
		return new WP_Error( 'rest_duplicate_items', sprintf( __( '%s has duplicate items.' ), $param ) );
	}

	return true;
}
```

## История изменений

- 5.7.0 — Introduced.

## Связанные

Использует: [`rest_sanitize_array`](https://chugunov.pro/api-wordpress/functions/rest_sanitize_array/), [`rest_validate_array_contains_unique_items`](https://chugunov.pro/api-wordpress/functions/rest_validate_array_contains_unique_items/), [`rest_is_array`](https://chugunov.pro/api-wordpress/functions/rest_is_array/), [`rest_validate_value_from_schema`](https://chugunov.pro/api-wordpress/functions/rest_validate_value_from_schema/), [`_n`](https://chugunov.pro/api-wordpress/functions/_n/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`number_format_i18n`](https://chugunov.pro/api-wordpress/functions/number_format_i18n/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/), `WP_Error::__construct`.
Используется в: [`rest_validate_value_from_schema`](https://chugunov.pro/api-wordpress/functions/rest_validate_value_from_schema/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/rest_validate_array_value_from_schema/
