carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Blocks do not work in 5.8 Wordpress widgets screen

Open thegreentimtam opened this issue 4 years ago • 8 comments

Version

  • Carbon Fields: 3.3.2
  • WordPress: 5.8
  • PHP: 7.3.21

Expected Behavior

I can edit and preview the block in the Widgets screen.

Actual Behavior

I recieve a "This block has encountered an error and cannot be previewed" error message.

Container definition

Block::make( 'hello', 'Hello' )
    ->add_fields( array(
        Field::make( 'text', 'person', 'Person' )
            ->set_default_value( 'World' )
    ) )
    ->set_render_callback( function( $fields ) {
        echo 'Hello ' . $fields[ 'person' ];
    });

Steps to Reproduce the Problem

  1. Create a block
  2. Add it to a sidebar in Wordpress 5.8

thegreentimtam avatar Jul 21 '21 01:07 thegreentimtam

Could this be because of the deprecated block_categories function? I see it is used here. I get this error when using the latest CarbonFields:

block_categories is <strong>deprecated</strong> since version 5.8.0! Use block_categories_all instead.

mikey242 avatar Jul 21 '21 08:07 mikey242

I tried switching out with block_categories_all as you did in your pull request ( #1024 ) but no luck.

thegreentimtam avatar Jul 21 '21 09:07 thegreentimtam

I think it might be something to do with the new way block assets are enqueued. Still trying to figure it out for one of my own projects. Do you get this error when wp_debug is enabled?

PHP Notice: wp_enqueue_script() was called <strong>incorrectly</strong>. "wp-editor" script should not be enqueued together with the new widgets editor (wp-edit-widgets or wp-customize-widgets).

More info here: https://core.trac.wordpress.org/ticket/53664

mikey242 avatar Jul 21 '21 09:07 mikey242

Do you get this error when wp_debug is enabled?

I'm not getting any PHP notices or errors and wp_debug is enabled. Just "This block has encountered an error and cannot be previewed" when I add the block to a sidebar.

The block displays correctly on the frontend sidebar, albeit with the default fields values.

thegreentimtam avatar Jul 22 '21 00:07 thegreentimtam

Any update on this one?

It's pretty sad for these awesome blocks to be broken :'(

Moustachos avatar Jun 21 '22 19:06 Moustachos

Yep, faced the same problem :( Created a block with just one text field. And it's working as expected in the post's editor, but not working in the widgets' editor ("Appearance"->"Widget"). I also see only "This block has encountered an error and cannot be previewed." message and don't see the field. I have WordPress 6.0.

terehof avatar Jun 23 '22 21:06 terehof

Still an problem with

  • WordPress: 6.4.3
  • Carbon Fields: 3.6.3
  • PHP: 8.1

Any updates on this issue?

XjSv avatar Feb 07 '24 19:02 XjSv

Is there any relation between this issue and this: https://github.com/Automattic/jetpack/issues/20357 ?

XjSv avatar Feb 07 '24 22:02 XjSv