For better or worse, WordPress 5.0 was released on Dec 6th, 2018 introducing the new block-based Gutenberg editor as an effective update. An update whose timing did not find the WordPress community completely united upon. However, it is certainly one that everyone within the ecosystem now has to adapt to.

For the past few months, we’ve been focusing our efforts on making Carbon Fields fully compatible with Gutenberg. We’ve added API for creating dynamic blocks, so you can use the same familiar field definition syntax to create rich Gutenberg blocks.

Today we release Carbon Fields version 3 which is available for install via Composer:

composer require htmlburger/carbon-fields

Creating Blocks

In Carbon Fields v3, you will see a new type of container called block . It allows developers to define blocks, as follows:

<?php use Carbon_Fields\Block; use Carbon_Fields\Field; Block::make( 'Flight' ) ->add_fields( [ Field::make( 'map', 'from' ), Field::make( 'date_time', 'departure_timestamp' ), Field::make( 'map', 'destination' ), Field::make( 'date_time', 'arrival_timestamp' ), ] ) ->set_render_callback( function( $flight ) { ?> <p> Flight departs from <?php echo esc_html( $flight['from']['address'] ) ?> at <?php echo $flight['departure_timestamp'] ?> and arrives to <?php echo esc_html( $flight['destination']['address'] ) ?> at <?php echo $flight['arrival_timestamp'] ?> </p> <?php });

From the user’s perspective, here is how this process goes:

You can read more about the block container in the documentation.



post_meta vs block containers

post_meta and block containers are quite different in purpose, as well as the way they store data.

The post_meta containers allow the user to edit meta information below the post body and store that data in the wp_postmeta .

They work in a similar way as in the classic edit screen:

The block containers, on the other hand, are used for a fundamentally different purpose. The values entered inside are stored in JSON objects within the HTML comments in the post_body instead of the wp_postmeta table. This allows users to add multiple copies of each block.

Having cleared up the difference, we could say that block containers are more of glorified shortcodes rather than replacements for the post_meta containers.

Custom fields for post revisions

Carbon Fields v3 introduces custom fields for post revisions, as well. This feature allows users to compare different custom fields’ values in the revision browser. It also allows previewing changes on the front end which were made in the custom fields.

Being first-row spectators of the development journey of WordPress sparks our excitement about what the future holds. Meanwhile, we’ll keep giving our best to maintain CarbonFields as one helpful tool in the hands of fellow developers.