# insert_hooked_blocks_into_rest_response()

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

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

## Сигнатура

```php
insert_hooked_blocks_into_rest_response( WP_REST_Response $response, WP_Post $post ): WP_REST_Response
```

## Описание

Подключается к ответу REST API для конечной точки Posts и добавляет первый и последний внутренние блоки.

## Параметры

- `$response` `WP_REST_Response` — обязательный. Объект ответа.
- `$post` `WP_Post` — обязательный. Объект записи.

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

`WP_REST_Response`

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

Файл: `wp-includes/blocks.php:1477`

```php
function insert_hooked_blocks_into_rest_response( $response, $post ) {
	if ( empty( $response->data['content']['raw'] ) ) {
		return $response;
	}

	$ignored_hooked_blocks_at_root    = array();
	$response->data['content']['raw'] = apply_block_hooks_to_content_from_post_object(
		$response->data['content']['raw'],
		$post,
		'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata',
		$ignored_hooked_blocks_at_root
	);

	if ( ! empty( $ignored_hooked_blocks_at_root ) ) {
		$response->data['meta']['_wp_ignored_hooked_blocks'] = wp_json_encode( $ignored_hooked_blocks_at_root );
	}

	// If the rendered content was previously empty, we leave it like that.
	if ( empty( $response->data['content']['rendered'] ) ) {
		return $response;
	}

	// `apply_block_hooks_to_content` is called above. Ensure it is not called again as a filter.
	$priority = has_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object' );
	if ( false !== $priority ) {
		remove_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority );
	}

	/** This filter is documented in wp-includes/post-template.php */
	$response->data['content']['rendered'] = apply_filters(
		'the_content',
		$response->data['content']['raw']
	);

	// Restore the filter if it was set initially.
	if ( false !== $priority ) {
		add_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', $priority );
	}

	return $response;
}
```

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

- 7.0.0 — Set _wp_ignored_hooked_blocks meta in the response for blocks hooked at the root level.
- 6.8.0 — Support non-wp_navigation post types.
- 6.6.0 — Introduced.

## Связанные

Использует: [`apply_block_hooks_to_content_from_post_object`](https://chugunov.pro/api-wordpress/functions/apply_block_hooks_to_content_from_post_object/), [`has_filter`](https://chugunov.pro/api-wordpress/functions/has_filter/), [`wp_json_encode`](https://chugunov.pro/api-wordpress/functions/wp_json_encode/), [`remove_filter`](https://chugunov.pro/api-wordpress/functions/remove_filter/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`add_filter`](https://chugunov.pro/api-wordpress/functions/add_filter/).
Используется в: `WP_REST_Posts_Controller::prepare_item_for_response`.

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