Home Forums Gutenberg Mixed variable types in render_callback in acf_register_block_type


Mixed variable types in render_callback in acf_register_block_type

  • When using the render_callback for acf_register_block_type in ACF 5.8, the third parameter $is_preview is boolean true in the editor and an array containing the block data in the frontend. This means that the result of using if($is_preview){ … } is always true, which is unexpected.

  • I am running into the same issue. In addition, $block['mode'] is equal to 'preview' on the frontend.

    • blakers

    • September 28, 2019 at 2:33 am

    This is happening for me as well, it appears to be when using the Gutenberg plugin as opposed to core Gutenberg. Core does not pass a 3rd variable so $is_preview would expect to default to false in the ACF render callback, but the Gutenberg plugin passes the full block array as a parameter which ACF’s function currently does not expect. I’m currently checking true === $is_preview to determine if it’s a preview because ACF explicitly sets it to true when this is the case.

  • @blakers you are a lifesaver! Thanks for that workaround, that will work great. I need access to the Group block, so until they add it to core Gutenberg I need to use the plugin.

    • dbishop

    • November 22, 2019 at 9:30 am

    Agreed! Thanks so much for the solution, @blakers

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.