# inject_ignored_hooked_blocks_metadata_attributes()

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

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

## Сигнатура

```php
inject_ignored_hooked_blocks_metadata_attributes( stdClass $changes, WP_REST_Request $deprecated = null ): stdClass|WP_Error
```

## Описание

По переданному объекту, представляющему объект записи wp_template или wp_template_part, подготовленный для вставки или обновления в базе данных, находит все блоки, имеющие прикреплённые блоки, и внедряет атрибут metadata.ignoredHookedBlocks в якорные блоки, чтобы отразить их.

## Параметры

- `$changes` `stdClass` — обязательный. Объект, представляющий шаблон или часть шаблона, подготовленный для вставки или обновления в базе данных.
- `$deprecated` `WP_REST_Request` — необязательный, по умолчанию `null`. Устаревший. Не используется.

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

`stdClass|WP_Error`

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

Файл: `wp-includes/block-template-utils.php:1703`

```php
function inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated = null ) {
	if ( null !== $deprecated ) {
		_deprecated_argument( __FUNCTION__, '6.5.3' );
	}

	if ( ! isset( $changes->post_content ) ) {
		return $changes;
	}

	$hooked_blocks = get_hooked_blocks();
	if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) {
		return $changes;
	}

	$meta  = $changes->meta_input ?? array();
	$terms = $changes->tax_input ?? array();

	if ( empty( $changes->ID ) ) {
		// There's no post object for this template in the database for this template yet.
		$post = $changes;
	} else {
		// Find the existing post object.
		$post = get_post( $changes->ID );

		// If the post is a revision, use the parent post's post_name and post_type.
		$post_id = wp_is_post_revision( $post );
		if ( $post_id ) {
			$parent_post     = get_post( $post_id );
			$post->post_name = $parent_post->post_name;
			$post->post_type = $parent_post->post_type;
		}

		// Apply the changes to the existing post object.
		$post = (object) array_merge( (array) $post, (array) $changes );

		$type_terms        = get_the_terms( $changes->ID, 'wp_theme' );
		$terms['wp_theme'] = ! is_wp_error( $type_terms ) && ! empty( $type_terms ) ? $type_terms[0]->name : null;
	}

	// Required for the WP_Block_Template. Update the post object with the current time.
	$post->post_modified = current_time( 'mysql' );

	// If the post_author is empty, set it to the current user.
	if ( empty( $post->post_author ) ) {
		$post->post_author = get_current_user_id();
	}

	if ( 'wp_template_part' === $post->post_type && ! isset( $terms['wp_template_part_area'] ) ) {
		$area_terms                     = get_the_terms( $changes->ID, 'wp_template_part_area' );
		$terms['wp_template_part_area'] = ! is_wp_error( $area_terms ) && ! empty( $area_terms ) ? $area_terms[0]->name : null;
	}

	$template = _build_block_template_object_from_post_object( new WP_Post( $post ), $terms, $meta );

	if ( is_wp_error( $template ) ) {
		return $template;
	}

	if ( 'wp_template_part' === $post->post_type ) {
		$attributes                     = array();
		$existing_ignored_hooked_blocks = isset( $post->ID ) ? get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true ) : '';

		if ( ! empty( $existing_ignored_hooked_blocks ) ) {
			$attributes['metadata'] = array(
				'ignoredHookedBlocks' => json_decode( $existing_ignored_hooked_blocks, true ),
			);
		}

		$content               = get_comment_delimited_block_content(
			'core/template-part',
			$attributes,
			$changes->post_content
		);
		$content               = apply_block_hooks_to_content( $content, $template, 'set_ignored_hooked_blocks_metadata' );
		$changes->post_content = remove_serialized_parent_block( $content );

		$wrapper_block_markup  = extract_serialized_parent_block( $content );
		$wrapper_block         = parse_blocks( $wrapper_block_markup )[0];
		$ignored_hooked_blocks = $wrapper_block['attrs']['metadata']['ignoredHookedBlocks'] ?? array();
		if ( ! empty( $ignored_hooked_blocks ) ) {
			if ( ! isset( $changes->meta_input ) ) {
				$changes->meta_input = array();
			}
			$changes->meta_input['_wp_ignored_hooked_blocks'] = wp_json_encode( $ignored_hooked_blocks );
		}
	} else {
		$changes->post_content = apply_block_hooks_to_content( $changes->post_content, $template, 'set_ignored_hooked_blocks_metadata' );
	}

	return $changes;
}
```

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

- 6.5.0 — Introduced.

## Связанные

Использует: [`extract_serialized_parent_block`](https://chugunov.pro/api-wordpress/functions/extract_serialized_parent_block/), [`_build_block_template_object_from_post_object`](https://chugunov.pro/api-wordpress/functions/_build_block_template_object_from_post_object/), [`apply_block_hooks_to_content`](https://chugunov.pro/api-wordpress/functions/apply_block_hooks_to_content/), [`remove_serialized_parent_block`](https://chugunov.pro/api-wordpress/functions/remove_serialized_parent_block/), [`get_hooked_blocks`](https://chugunov.pro/api-wordpress/functions/get_hooked_blocks/), [`get_comment_delimited_block_content`](https://chugunov.pro/api-wordpress/functions/get_comment_delimited_block_content/), [`parse_blocks`](https://chugunov.pro/api-wordpress/functions/parse_blocks/), [`get_the_terms`](https://chugunov.pro/api-wordpress/functions/get_the_terms/), [`current_time`](https://chugunov.pro/api-wordpress/functions/current_time/), [`has_filter`](https://chugunov.pro/api-wordpress/functions/has_filter/), `WP_Post::__construct`, [`wp_is_post_revision`](https://chugunov.pro/api-wordpress/functions/wp_is_post_revision/), [`wp_json_encode`](https://chugunov.pro/api-wordpress/functions/wp_json_encode/), [`_deprecated_argument`](https://chugunov.pro/api-wordpress/functions/_deprecated_argument/), [`get_current_user_id`](https://chugunov.pro/api-wordpress/functions/get_current_user_id/), [`get_post_meta`](https://chugunov.pro/api-wordpress/functions/get_post_meta/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).

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