# register_block_style_handle()

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

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

## Сигнатура

```php
register_block_style_handle( array $metadata, string $field_name, int $index ): string|false
```

## Описание

Находит дескриптор стиля для поля метаданных блока. Определяет, когда указан путь к файлу, и регистрирует стиль под автоматически сгенерированным именем дескриптора. Иначе возвращает необработанный дескриптор стиля.

## Параметры

- `$metadata` `array` — обязательный. Метаданные блока.
- `$field_name` `string` — обязательный. Имя поля, выбираемого из метаданных.
- `$index` `int` — необязательный. Индекс стиля для регистрации, когда передано несколько элементов.
  
  Значение по умолчанию 0.

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

`string|false`

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

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

```php
function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
	if ( empty( $metadata[ $field_name ] ) ) {
		return false;
	}

	$style_handle = $metadata[ $field_name ];
	if ( is_array( $style_handle ) ) {
		if ( empty( $style_handle[ $index ] ) ) {
			return false;
		}
		$style_handle = $style_handle[ $index ];
	}

	$style_handle_name = generate_block_asset_handle( $metadata['name'], $field_name, $index );
	// If the style handle is already registered, skip re-registering.
	if ( wp_style_is( $style_handle_name, 'registered' ) ) {
		return $style_handle_name;
	}

	static $wpinc_path_norm = '';
	if ( ! $wpinc_path_norm ) {
		$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
	}

	$is_core_block = isset( $metadata['file'] ) && str_starts_with( $metadata['file'], $wpinc_path_norm );
	// Skip registering individual styles for each core block when a bundled version provided.
	if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) {
		return false;
	}

	$style_path      = remove_block_asset_path_prefix( $style_handle );
	$is_style_handle = $style_handle === $style_path;
	// Allow only passing style handles for core blocks.
	if ( $is_core_block && ! $is_style_handle ) {
		return false;
	}
	// Return the style handle unless it's the first item for every core block that requires special treatment.
	if ( $is_style_handle && ! ( $is_core_block && 0 === $index ) ) {
		return $style_handle;
	}

	// Check whether styles should have a ".min" suffix or not.
	$suffix = SCRIPT_DEBUG ? '' : '.min';
	if ( $is_core_block ) {
		$style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
	}

	$style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) );
	$style_uri       = get_block_asset_url( $style_path_norm );

	$block_version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false;
	$version       = $style_path_norm && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? filemtime( $style_path_norm ) : $block_version;
	$result        = wp_register_style(
		$style_handle_name,
		$style_uri,
		array(),
		$version
	);
	if ( ! $result ) {
		return false;
	}

	if ( $style_uri ) {
		wp_style_add_data( $style_handle_name, 'path', $style_path_norm );

		if ( $is_core_block ) {
			$rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $style_path_norm );
		} else {
			$rtl_file = str_replace( '.css', '-rtl.css', $style_path_norm );
		}

		if ( is_rtl() && file_exists( $rtl_file ) ) {
			wp_style_add_data( $style_handle_name, 'rtl', 'replace' );
			wp_style_add_data( $style_handle_name, 'suffix', $suffix );
			wp_style_add_data( $style_handle_name, 'path', $rtl_file );
		}
	}

	return $style_handle_name;
}
```

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

- 6.1.0 — Added $index parameter.
- 5.5.0 — Introduced.

## Связанные

Использует: [`get_block_asset_url`](https://chugunov.pro/api-wordpress/functions/get_block_asset_url/), [`wp_should_load_separate_core_block_assets`](https://chugunov.pro/api-wordpress/functions/wp_should_load_separate_core_block_assets/), [`generate_block_asset_handle`](https://chugunov.pro/api-wordpress/functions/generate_block_asset_handle/), [`remove_block_asset_path_prefix`](https://chugunov.pro/api-wordpress/functions/remove_block_asset_path_prefix/), [`wp_normalize_path`](https://chugunov.pro/api-wordpress/functions/wp_normalize_path/), [`is_rtl`](https://chugunov.pro/api-wordpress/functions/is_rtl/), [`wp_style_is`](https://chugunov.pro/api-wordpress/functions/wp_style_is/), [`wp_register_style`](https://chugunov.pro/api-wordpress/functions/wp_register_style/), [`wp_style_add_data`](https://chugunov.pro/api-wordpress/functions/wp_style_add_data/).
Используется в: [`register_block_type_from_metadata`](https://chugunov.pro/api-wordpress/functions/register_block_type_from_metadata/).

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