Skip to content

Commit

Permalink
Merge pull request #3 from dsturm/master
Browse files Browse the repository at this point in the history
Improve block registration for already registered blocks
  • Loading branch information
kellymears authored Aug 17, 2020
2 parents a293724 + a24b806 commit e019602
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Providers/BlockTemplatesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function register(): void
{
$this->blocks = Collection::make();

add_action('init', [$this, 'registerBlockTemplates'], 9);
add_action('init', [$this, 'registerBlockTemplates']);
}

/**
Expand All @@ -44,11 +44,19 @@ public function boot(): void
public function registerBlockTemplates(): void
{
$this->blocks->each(function ($block) {
register_block_type($block, [
$args = [
'render_callback' => function ($attributes, $content) use ($block) {
return $this->renderBlock($block, $attributes, $content);
},
]);
];

$blockType = \WP_Block_Type_Registry::get_instance()->get_registered($block);

if ($blockType) {
return $blockType->set_props($args);
}

register_block_type($block, $args);
});
}

Expand Down

0 comments on commit e019602

Please sign in to comment.