Issue:
It seems that ACF uses a custom AJAX action/callback for rendering block previews in the editor: acf_ajax_fetch_block and acf_rendered_block/acf_render_block directly.
On the frontend, the rendering of the block is done by WP cores render_block and WP_Block::render. This render functions call the following filters:
render_block_data
render_block_context
and they setup the WP_Block_Supports class which is required for get_block_wrapper_attributes to work.
This means, that when an ACF block is rendered in the editor, it does not call these hooks. We use render_block_data for some helpers and we also use get_block_wrapper_attributes much in our block templates (which does some block-supports magic and also adds the default block class name) - as suggested by WordPress core documentation.
Reproducing:
Add a callback filter to render_block_data to change some block attributes data. See how it get's called when rendering a custom block on the frontend but not when the preview is rendered on the backend.
Use get_block_wrapper_attributes in your block template. See how it works when rendering a custom block on the frontend but not when the preview is rendered on the backend. It even triggers a PHP warning.
Suggested fix: ACF should use render_block to render block previews so it's certainly the same output as on the frontend.
Issue: It seems that ACF uses a custom AJAX action/callback for rendering block previews in the editor:
acf_ajax_fetch_block
andacf_rendered_block
/acf_render_block
directly. On the frontend, the rendering of the block is done by WP coresrender_block
andWP_Block::render
. This render functions call the following filters:render_block_data
render_block_context
WP_Block_Supports
class which is required forget_block_wrapper_attributes
to work.This means, that when an ACF block is rendered in the editor, it does not call these hooks. We use
render_block_data
for some helpers and we also useget_block_wrapper_attributes
much in our block templates (which does some block-supports magic and also adds the default block class name) - as suggested by WordPress core documentation.Reproducing:
render_block_data
to change some block attributes data. See how it get's called when rendering a custom block on the frontend but not when the preview is rendered on the backend.get_block_wrapper_attributes
in your block template. See how it works when rendering a custom block on the frontend but not when the preview is rendered on the backend. It even triggers a PHP warning.Suggested fix: ACF should use render_block to render block previews so it's certainly the same output as on the frontend.
Version: ACF Version: 6.0.3 WordPress Version: 6.0 PHP Version: 8.0 ACF Block-Version: 1 (via acf_register_block_type)