# rest_cookie_check_errors()

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

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

## Сигнатура

```php
rest_cookie_check_errors( WP_Error|mixed $result ): WP_Error|mixed|bool
```

## Описание

Встроенная в WordPress аутентификация по cookie всегда активна для вошедших пользователей. Однако API вынужден проверять одноразовые защитные коды для каждого запроса, чтобы пользователи не были уязвимы к CSRF.

## Параметры

- `$result` `WP_Error|mixed` — обязательный. Ошибка от другого обработчика аутентификации; null, если её должны обработать мы, либо иное значение в противном случае.

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

`WP_Error|mixed|bool` — WP_Error

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

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

```php
function rest_cookie_check_errors( $result ) {
	if ( ! empty( $result ) ) {
		return $result;
	}

	global $wp_rest_auth_cookie;

	/*
	 * Is cookie authentication being used? (If we get an auth
	 * error, but we're still logged in, another authentication
	 * must have been used).
	 */
	if ( true !== $wp_rest_auth_cookie && is_user_logged_in() ) {
		return $result;
	}

	// Determine if there is a nonce.
	$nonce = null;

	if ( isset( $_REQUEST['_wpnonce'] ) ) {
		$nonce = $_REQUEST['_wpnonce'];
	} elseif ( isset( $_SERVER['HTTP_X_WP_NONCE'] ) ) {
		$nonce = $_SERVER['HTTP_X_WP_NONCE'];
	}

	if ( null === $nonce ) {
		// No nonce at all, so act as if it's an unauthenticated request.
		wp_set_current_user( 0 );
		return true;
	}

	// Check the nonce.
	$result = wp_verify_nonce( $nonce, 'wp_rest' );

	if ( ! $result ) {
		add_filter( 'rest_send_nocache_headers', '__return_true', 20 );
		return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) );
	}

	// Send a refreshed nonce in header.
	rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );

	return true;
}
```

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

- 4.4.0 — Introduced.

## Связанные

Использует: [`rest_get_server`](https://chugunov.pro/api-wordpress/functions/rest_get_server/), [`wp_verify_nonce`](https://chugunov.pro/api-wordpress/functions/wp_verify_nonce/), [`wp_set_current_user`](https://chugunov.pro/api-wordpress/functions/wp_set_current_user/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`wp_create_nonce`](https://chugunov.pro/api-wordpress/functions/wp_create_nonce/), [`is_user_logged_in`](https://chugunov.pro/api-wordpress/functions/is_user_logged_in/), [`add_filter`](https://chugunov.pro/api-wordpress/functions/add_filter/), `WP_Error::__construct`.

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