55defined ('ABSPATH ' ) || exit;
66
77use StarterKit \Error \ErrorHandler ;
8- use StarterKit \Helper \Config ;
98use StarterKit \Exception \ConfigEntryNotFoundException ;
9+ use StarterKit \Helper \Config ;
1010use StarterKitBlocks ;
1111use Throwable ;
1212
@@ -44,17 +44,24 @@ public static function loadBlocksCategories(array $categories): array
4444 /**
4545 * Register all blocks in blocks directory
4646 *
47+ * @param string $blocksDir Custom blocks directory path
48+ * @param string $namespace Custom namespace for blocks
49+ *
4750 * @return void
4851 *
4952 * @throws Throwable
5053 */
51- public static function loadBlocks (): void
54+ public static function loadBlocks (string $ blocksDir = '' , string $ namespace = '' ): void
5255 {
5356 if (!function_exists ('register_block_type_from_metadata ' )) {
5457 return ;
5558 }
5659
57- $ blocks = glob (SK_BLOCKS_DIR . '* ' , GLOB_ONLYDIR );
60+ // Use provided directory or default theme blocks directory
61+ $ blocksDir = !empty ($ blocksDir ) ? $ blocksDir : SK_BLOCKS_DIR ;
62+ $ namespace = !empty ($ namespace ) ? $ namespace : 'StarterKitBlocks ' ;
63+
64+ $ blocks = glob ($ blocksDir . '* ' , GLOB_ONLYDIR );
5865
5966 foreach ($ blocks as $ blockPath ) {
6067 $ blockName = basename ($ blockPath );
@@ -65,7 +72,7 @@ public static function loadBlocks(): void
6572 }
6673
6774 // Assuming each block has a BlockRenderer class in the appropriate namespace
68- $ Block = ' StarterKitBlocks \\' . $ blockName . '\\Block ' ;
75+ $ Block = $ namespace . ' \\' . $ blockName . '\\Block ' ;
6976
7077 // Instantiate the block class
7178 try {
@@ -79,13 +86,13 @@ public static function loadBlocks(): void
7986 public static function addSpacerAttributeToBlocks ($ args ): array
8087 {
8188 $ args ['attributes ' ]['spacers ' ] = [
82- 'type ' => 'object ' ,
89+ 'type ' => 'object ' ,
8390 'default ' => [
84- 'xs ' => [],
85- 'sm ' => [],
86- 'md ' => [],
87- 'lg ' => [],
88- 'xl ' => [],
91+ 'xs ' => [],
92+ 'sm ' => [],
93+ 'md ' => [],
94+ 'lg ' => [],
95+ 'xl ' => [],
8996 'xxl ' => [],
9097 ],
9198 ];
0 commit comments