File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments