# _block_bindings_post_data_get_value()

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

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

## Сигнатура

```php
_block_bindings_post_data_get_value( array $source_args, WP_Block $block_instance ): mixed
```

## Описание

Получает значение для источника данных записи (Post Data).

## Параметры

- `$source_args` `array` — обязательный. Массив с аргументами, используемыми для поиска значения источника.
  
  Пример: array( "field" => "foo" ).
- `$block_instance` `WP_Block` — обязательный. Экземпляр блока.

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

`mixed`

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

Файл: `wp-includes/block-bindings/post-data.php:21`

```php
function _block_bindings_post_data_get_value( array $source_args, $block_instance ) {
	if ( empty( $source_args['field'] ) ) {
		// Backward compatibility for when the source argument was called `key` in Gutenberg plugin.
		if ( empty( $source_args['key'] ) ) {
			return null;
		}
		$field = $source_args['key'];
	} else {
		$field = $source_args['field'];
	}

	/*
	 * BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
	 * Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
	 */
	$block_name          = $block_instance->name ?? '';
	$is_navigation_block = in_array(
		$block_name,
		array( 'core/navigation-link', 'core/navigation-submenu' ),
		true
	);

	if ( $is_navigation_block ) {
		// Navigation blocks: read from block attributes.
		$post_id = $block_instance->attributes['id'] ?? null;
	} else {
		// All other blocks: use context.
		$post_id = $block_instance->context['postId'] ?? null;
	}

	// If we don't have an entity ID, bail early.
	if ( empty( $post_id ) ) {
		return null;
	}

	// If a post isn't public, we need to prevent unauthorized users from accessing the post data.
	$post = get_post( $post_id );
	if ( ( ! is_post_publicly_viewable( $post ) && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post ) ) {
		return null;
	}

	if ( 'date' === $field ) {
		return esc_attr( get_the_date( 'c', $post_id ) );
	}

	if ( 'modified' === $field ) {
		// Only return the modified date if it is later than the publishing date.
		if ( get_the_modified_date( 'U', $post_id ) > get_the_date( 'U', $post_id ) ) {
			return esc_attr( get_the_modified_date( 'c', $post_id ) );
		} else {
			return '';
		}
	}

	if ( 'link' === $field ) {
		$permalink = get_permalink( $post_id );
		return false === $permalink ? null : esc_url( $permalink );
	}
}
```

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

- 6.9.0 — Introduced.

## Связанные

Использует: [`is_post_publicly_viewable`](https://chugunov.pro/api-wordpress/functions/is_post_publicly_viewable/), [`get_the_modified_date`](https://chugunov.pro/api-wordpress/functions/get_the_modified_date/), [`get_the_date`](https://chugunov.pro/api-wordpress/functions/get_the_date/), [`post_password_required`](https://chugunov.pro/api-wordpress/functions/post_password_required/), [`current_user_can`](https://chugunov.pro/api-wordpress/functions/current_user_can/), [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`get_permalink`](https://chugunov.pro/api-wordpress/functions/get_permalink/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).

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