ΠΡΠΈΠ²Π΅Ρ Π²ΡΠ΅ΠΌ, Π½Π°ΡΠΊΠΎΠ»ΡΠΊΠΎ Ρ ΠΏΠΎΠ½ΡΠ», ΡΡΡ ΠΈ ΠΏΠΎ-ΡΡΡΡΠΊΠΈ ΡΠ°Π·Π³ΠΎΠ²Π°ΡΠΈΠ²Π°ΡΡ? Π£ ΠΌΠ΅Π½Ρ Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ΠΏΡΠΎΠ±Π»Π΅ΠΌΠ° ΠΏΡΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠΈ Π±Π»ΠΎΠΊΠΎΠ² Gutenberg. ΠΠ΅ΡΡ ΠΏΡΠΈΠΌΠ΅Ρ ΠΈΠ· Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ ΠΈ Π²ΡΡΠ°Π²Π»ΡΡ Π΅Π³ΠΎ ΠΊΠ°ΠΊ Π΅ΡΡΡ.
`
use Carbon_Fields\Block;
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
} );
Π ΠΈΡΠΎΠ³Π΅ Ρ ΠΌΠ΅Π½Ρ Π²ΡΠ΄Π°Π΅Ρ ΠΎΡΠΈΠ±ΠΊΡ:
Fatal error: Uncaught Error: Class 'Carbon_Fields\Block' not found in.
Π§ΡΠΎ Ρ Π΄Π΅Π»Π°Ρ Π½Π΅ ΡΠ°ΠΊ? ΠΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ CarbonFields:
function crb_load() {
require_once( 'inc/vendor/autoload.php' );
\Carbon_Fields\Carbon_Fields::boot();
}
add_action( 'after_setup_theme', 'crb_load' );
`
Hi @Hellion35
Could you please make sure that you're using Carbon Fields version 3? I guess that you're using older version of the library.
I have same issue. I am using this version - https://carbonfields.net/zip/v3.1.2/ . It is a bug or file missing, but other things (theme option, metabox, widget etc) work fine just have issue with guttenberg block.
Can you please recheck @emohamed ?
I know this will be very obvious for most, but for me I had failed to switch to the theme where I had installed Carbon Fields. Embarrassingly this took me 10 - 15 minutes to realize.
Hi @Hellion35,
You should register your blocks after the boot method call.
function crb_load() {
require_once( 'inc/vendor/autoload.php' );
\Carbon_Fields\Carbon_Fields::boot();
// Register your blocks here...
}
add_action( 'after_setup_theme', 'crb_load' );
@webangon, Can you try the same thing? :)
In terms of developer-friendliness, could this boot process be done automatically by the plugin under the hood, so that instructions get simpler and more consistent, like:
Define your blocks within the action_X hook or any action hook between X and Z
(X and Z being part of https://codex.wordpress.org/Plugin_API/Action_Reference)
I been using 3.1.2 version, (Plugin Edition).
Register the component under carbon_fields_register_fields hooks works fine for me.
add_action( 'carbon_fields_register_fields', 'custom_function_to_register_block' );
Full sample code: github gist
Most helpful comment
In terms of developer-friendliness, could this boot process be done automatically by the plugin under the hood, so that instructions get simpler and more consistent, like:
Define your blocks within the action_X hook or any action hook between X and Z(X and Z being part of https://codex.wordpress.org/Plugin_API/Action_Reference)