Skip to content

Commit

Permalink
chore(block): use acf_register_block_type instead of `acf_register_…
Browse files Browse the repository at this point in the history
…block` (#124)

* enhance(block): Conditionally check if example is not null before setting it (Temp Fix for #123)
  • Loading branch information
Log1x authored Aug 13, 2022
1 parent a1f2ba4 commit 541aba1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function compose()
}

$this->register(function () {
acf_register_block([
$settings = [
'name' => $this->slug,
'title' => $this->name,
'description' => $this->description,
Expand All @@ -258,19 +258,24 @@ public function compose()
'align_content' => $this->align_content,
'styles' => $this->styles,
'supports' => $this->supports,
'example' => [
'attributes' => [
'mode' => 'preview',
'data' => $this->example,
]
],
'enqueue_assets' => function () {
return $this->enqueue();
},
'render_callback' => function ($block, $content = '', $preview = false, $post_id = 0) {
echo $this->render($block, $content, $preview, $post_id);
}
]);
},
];

if (! empty($this->example)) {
$settings = Arr::add($settings, 'example', [
'attributes' => [
'mode' => 'preview',
'data' => $this->example,
],
]);
}

acf_register_block_type($settings);
});

return $this;
Expand Down

0 comments on commit 541aba1

Please sign in to comment.