From 4703ef6c7492f261851ab2a994aba5b856c4fc58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Folbert?= Date: Sun, 5 Jun 2022 17:57:25 +0200 Subject: [PATCH] Make render use $wp_block and $context $wp_block and $context is passed by ACF to the render callback function. --- src/Block.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Block.php b/src/Block.php index 1aa8601..e7baa9e 100644 --- a/src/Block.php +++ b/src/Block.php @@ -38,6 +38,16 @@ abstract class Block extends Composer implements BlockContract * @param int */ public $post; + + /** + * @var \WP_Block|null + */ + public $wp_block; + + /** + * @var array|false + */ + public $context; /** * The block classes. @@ -267,8 +277,8 @@ public function compose() 'enqueue_assets' => function () { return $this->enqueue(); }, - 'render_callback' => function ($block, $content = '', $preview = false, $post_id = 0) { - echo $this->render($block, $content, $preview, $post_id); + 'render_callback' => function ($block, $content = '', $preview = false, $post_id = 0, $wp_block = null, $context = false) { + echo $this->render($block, $content, $preview, $post_id, $wp_block, $context); } ]); }); @@ -283,13 +293,17 @@ public function compose() * @param string $content * @param bool $preview * @param int $post_id + * @param \WP_Block|null $wp_block + * @param array|bool $context * @return string */ - public function render($block, $content = '', $preview = false, $post_id = 0) + public function render($block, $content = '', $preview = false, $post_id = 0, $wp_block = null, $context = false) { $this->block = (object) $block; $this->content = $content; $this->preview = $preview; + $this->wp_block = $wp_block; + $this->context = $context; $this->post = get_post($post_id); $this->post_id = $post_id;