Skip to content

Commit 91c0b7f

Browse files
authored
Merge pull request #7 from micropackage/feat/block-wrap-attributes
feat: render block wrapper attributes
2 parents ff7a255 + bd88a01 commit 91c0b7f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
## [Next]
55

6+
* [Added] Render block wrapper attributes
67
* [Added] Support for block spacing
78

89
## 1.0.6

src/BlockLoader.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ protected function __construct( $config ) {
8888
wp_parse_args( $config, [
8989
'dir' => 'blocks',
9090
'categories' => [],
91-
'wrap' => '<div id="%3$s" class="%2$s">%1$s</div>',
91+
'wrap' => $this->supports_block_wrapper_attributes()
92+
? '<div id="%3$s" %4$s>%1$s</div>'
93+
: '<div id="%3$s" class="%2$s">%1$s</div>',
9294
'default_category' => false,
9395
'root_dir' => get_stylesheet_directory(),
9496
] )
@@ -390,14 +392,27 @@ public function render_block( $block ) {
390392
$wrap_html,
391393
$block_content,
392394
esc_attr( $class ),
393-
esc_attr( $this->get_unique_block_id( $block['slug'] ) )
395+
esc_attr( $this->get_unique_block_id( $block['slug'] ) ),
396+
$this->supports_block_wrapper_attributes()
397+
? get_block_wrapper_attributes( [ 'class' => $class ] )
398+
: ''
394399
);
395400
} else {
396401
echo $block_content;
397402
// phpcs:enable
398403
}
399404
}
400405

406+
/**
407+
* Checks whether WordPress supports block wrapper attributes.
408+
*
409+
* @since [Next]
410+
* @return bool
411+
*/
412+
protected function supports_block_wrapper_attributes() {
413+
return function_exists( 'get_block_wrapper_attributes' );
414+
}
415+
401416
/**
402417
* Magic config getter
403418
*

0 commit comments

Comments
 (0)