undefined method 'set_render_callback'
sakralbar opened this issue · 2 comments
sakralbar commented
Version
- Carbon Fields: 3.6.3
- WordPress: 6.4.3
- PHP: 8.1.2
Expected Behavior
Working example with create gutenberg block.
Actual Behavior
Example not working. Got errror "undefined method 'set_render_callback'".
Container definition
use Carbon_Fields\Block;
use Carbon_Fields\Field;
Block::make(__('My Shiny Gutenberg Block'))
->add_fields(array(
Field::make('text', 'heading', __('Block Heading')),
Field::make('image', 'image', __('Block Image')),
Field::make('rich_text', 'content', __('Block Content')),
))
->set_render_callback(function ($fields, $attributes, $inner_blocks) {
?>
<div class="block">
<div class="block__heading">
<h1><?php echo esc_html($fields['heading']); ?></h1>
</div><!-- /.block__heading -->
<div class="block__image">
<?php echo wp_get_attachment_image($fields['image'], 'full'); ?>
</div><!-- /.block__image -->
<div class="block__content">
<?php echo apply_filters('the_content', $fields['content']); ?>
</div><!-- /.block__content -->
</div><!-- /.block -->
<?php
});
Steps to Reproduce the Problem
- Install carbon fields via composer.
- Add example code to create gutenberg block into functions.php
- Vscode show error (undefined method), no block in block editor.
emohamed commented
Could you please confirm that you've booted Carbon Fields?
Carbon_Fields::boot();
If the problem persist, could you please enable WP_DEBUG
in your wp-config file and let us know if you can see the PHP error in your browser -- I suspect that the VSCode error that you're seeing is probably false alert.
sakralbar commented
This is my mistake. Carbon fields was installed at the root of the site, not the template.
Sorry and thanks for the reply.