@@ -30,17 +30,22 @@ function register_block_categories( $categories ) {
3030function 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