Skip to content

Commit 4dce1aa

Browse files
committed
edit custom native block registering to register blocks that have subblocks, ref DEV-56
1 parent a905d77 commit 4dce1aa

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

inc/hooks/native-gutenberg-blocks.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ function register_block_categories( $categories ) {
3030
function register_native_gutenberg_blocks() {
3131
// Get all directories in the blocks folder
3232
$blocks_dir = get_theme_file_path( '/blocks' );
33-
$block_folders = array_filter( glob( $blocks_dir . '/*' ), 'is_dir' );
3433

35-
foreach ( $block_folders as $block_folder ) {
36-
// Check if block.json exists in the build folder
37-
if ( file_exists( $block_folder . '/build/block.json' ) ) {
38-
// Add error logging to debug block registration
39-
$registration_result = register_block_type( $block_folder . '/build' );
34+
// Get all singular blocks
35+
$blocks = glob( $blocks_dir . '/*/build/block.json' );
4036

41-
if ( is_wp_error( $registration_result ) ) {
42-
error_log( 'Block registration error for ' . basename( $block_folder ) . ': ' . $registration_result->get_error_message() );
43-
}
37+
// Get all blocks that have multiple blocks
38+
$inner_blocks = glob( $blocks_dir . '/*/build/*/block.json' );
39+
40+
// Combine blocks
41+
$blocks = array_merge( $blocks, $inner_blocks );
42+
43+
foreach ( $blocks as $block_folder ) {
44+
// Add error logging to debug block registration
45+
$registration_result = register_block_type( str_replace( '/block.json', '', $block_folder ) );
46+
47+
if ( is_wp_error( $registration_result ) ) {
48+
error_log( 'Block registration error for ' . basename( $block_folder ) . ': ' . $registration_result->get_error_message() );
4449
}
4550
}
4651
}

0 commit comments

Comments
 (0)