Skip to content

Commit

Permalink
Make render use $wp_block and $context
Browse files Browse the repository at this point in the history
$wp_block and $context is passed by ACF to the render callback function.
  • Loading branch information
folbert committed Jun 5, 2022
1 parent f3efa1b commit 4703ef6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Block.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
]);
});
Expand All @@ -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;
Expand Down

0 comments on commit 4703ef6

Please sign in to comment.