# rest_api_loaded()

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

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

## Сигнатура

```php
rest_api_loaded()
```

## Описание

Загружает REST API.

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

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

```php
function rest_api_loaded() {
	if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
		return;
	}

	// Return an error message if query_var is not a string.
	if ( ! is_string( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
		$rest_type_error = new WP_Error(
			'rest_path_invalid_type',
			__( 'The REST route parameter must be a string.' ),
			array( 'status' => 400 )
		);
		wp_die( $rest_type_error );
	}

	/**
	 * Whether this is a REST Request.
	 *
	 * @since 4.4.0
	 * @var bool
	 */
	define( 'REST_REQUEST', true );

	// Initialize the server.
	$server = rest_get_server();

	// Fire off the request.
	$route = untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] );
	if ( empty( $route ) ) {
		$route = '/';
	}
	$server->serve_request( $route );

	// We're done.
	die();
}
```

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

- 4.4.0 — Introduced.

## Связанные

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

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