block_core_gallery_data_id_backcompatibility()WP 1.0

Handles backwards compatibility for Gallery Blocks, whose images feature a data-id attribute.

Now that the Gallery Block contains inner Image Blocks, we add a custom data-id attribute before rendering the gallery so that the Image Block can pick it up in its render_callback.

Хуков нет.

Возвращает

Массив. The migrated block object.

Использование

block_core_gallery_data_id_backcompatibility( $parsed_block );
$parsed_block(массив) (обязательный)
The block being rendered.

Код block_core_gallery_data_id_backcompatibility() WP 6.0.2

function block_core_gallery_data_id_backcompatibility( $parsed_block ) {
	if ( 'core/gallery' === $parsed_block['blockName'] ) {
		foreach ( $parsed_block['innerBlocks'] as $key => $inner_block ) {
			if ( 'core/image' === $inner_block['blockName'] ) {
				if ( ! isset( $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] ) && isset( $inner_block['attrs']['id'] ) ) {
					$parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] = esc_attr( $inner_block['attrs']['id'] );
				}
			}
		}
	}

	return $parsed_block;
}