Skip to content

Commit e6e7fc6

Browse files
committed
update loadBlocks function - use folder and namespace parameters
1 parent a9c75db commit e6e7fc6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/Base/Hooks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public static function initHooks(): void
5353
add_action('init', [Handlers\PostTypes\News::class, 'registerPostType'], 5);
5454
add_action('init', [Handlers\PostTypes\News::class, 'registerCategoryTaxonomy'], 5);
5555
add_action('init', [Handlers\PostTypes\News::class, 'registerTagTaxonomy'], 5);
56-
add_action('init', [Handlers\PostTypes\Portfolio::class, 'registerPostType'], 5);
5756
add_action('init', [Handlers\PostTypes\TeamMember::class, 'registerPostType'], 5);
5857
add_action('init', [Handlers\PostTypes\Service::class, 'registerPostType'], 5);
5958

src/Handlers/Blocks/Init.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
defined('ABSPATH') || exit;
66

77
use StarterKit\Error\ErrorHandler;
8-
use StarterKit\Helper\Config;
98
use StarterKit\Exception\ConfigEntryNotFoundException;
9+
use StarterKit\Helper\Config;
1010
use StarterKitBlocks;
1111
use 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

Comments
 (0)