# rest_get_server()

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

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

## Сигнатура

```php
rest_get_server(): WP_REST_Server
```

## Описание

Создаёт новый экземпляр, если он ещё не существует.

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

`WP_REST_Server`

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

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

```php
function rest_get_server() {
	/* @var WP_REST_Server $wp_rest_server */
	global $wp_rest_server;

	if ( empty( $wp_rest_server ) ) {
		/**
		 * Filters the REST Server Class.
		 *
		 * This filter allows you to adjust the server class used by the REST API, using a
		 * different class to handle requests.
		 *
		 * @since 4.4.0
		 *
		 * @param string $class_name The name of the server class. Default 'WP_REST_Server'.
		 */
		$wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' );
		$wp_rest_server       = new $wp_rest_server_class();

		/**
		 * Fires when preparing to serve a REST API request.
		 *
		 * Endpoint objects should be created and register their hooks on this action rather
		 * than another action to ensure they're only loaded when needed.
		 *
		 * @since 4.4.0
		 *
		 * @param WP_REST_Server $wp_rest_server Server object.
		 */
		do_action( 'rest_api_init', $wp_rest_server );
	}

	return $wp_rest_server;
}
```

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

- 4.5.0 — Introduced.

## Связанные

Использует: [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/).
Используется в: `WP_REST_Server::get_target_hints_for_link`, [`rest_preload_api_request`](https://chugunov.pro/api-wordpress/functions/rest_preload_api_request/), `WP_REST_Controller::prepare_response_for_collection`, [`rest_cookie_check_errors`](https://chugunov.pro/api-wordpress/functions/rest_cookie_check_errors/), [`rest_do_request`](https://chugunov.pro/api-wordpress/functions/rest_do_request/), [`rest_api_loaded`](https://chugunov.pro/api-wordpress/functions/rest_api_loaded/), [`register_rest_route`](https://chugunov.pro/api-wordpress/functions/register_rest_route/).

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