3.6.6 Front end displays blank caused by ob_get_contents() being blank
We recently updated to WP 6.8.1 and noticed that while on carbon fields 3.6.3 blocks were being rendered in the front end but were not appearing in the editor and were showing up as missing blocks, we have included the sample block definition below.
Updating to 3.6.6 resolves this issue, however the front end of the website is now blank with no HTML being generated while debug mode is off, when it is on it is rendering, we've ruled out any other composer packages causing this issue.
public function register() {
Block::make(__('helloworld', $this->text_domain))
->set_description('Hello World')
->set_icon('list-view')
->set_mode('both')
->set_inner_blocks(true)
->set_inner_blocks_position('below')
->set_inner_blocks_template(array(
array('core/paragraph', array(
'placeholder' => 'Content goes here',
)),
))
->set_category('custom-blocks', __('Blocks', $this->text_domain))
->set_render_callback(function ($fields, $attributes, $inner_blocks) {
$vars['fields'] = $fields;
$vars['content'] = $inner_blocks;
$vars['attributes'] = $attributes;
$vars['index'] = uniqid();
Timber::render('/blocks/accordion.html.twig', $vars);
});
}
Using 3.6.6 we have made these following changes and the front end issue has resolved the issue on our end.
core/container/Block_Container.php
/**
* Render the block type.
*
* @param array $attributes
* @param string $content
* @param \WP_Block $block
* @return string
*/
public function render_block( $attributes, $content, $block = null ) {
$fields = $attributes['data'];
$post_id = $this->get_post_id();
// Unset the "data" property because we
// pass it as separate argument to the callback.
unset($attributes['data']);
ob_start();
call_user_func( $this->render_callback , $fields, $attributes, $content, $post_id, $block );
return ob_get_clean();
}
Can confirm, behaves the same for me – all pages that contain Carbon Fields blocks are blank on frontend (no HTML generated), all the other pages work.
Reproduced with WordPress 6.8.1, PHP 8.2, Carbon Fields 3.6.6.
Your fix works. Setting WP_DEBUG to true helps as well.
This is fixed in 3.6.8
This is fixed in 3.6.8
Where can I get version 3.6.8?
This is fixed in 3.6.8
Where can I get version 3.6.8?