AdvancedCustomFields / acf

Advanced Custom Fields
http://advancedcustomfields.com/
833 stars 169 forks source link

ACF skips WP_Block::render for preview in Editor #745

Open gaambo opened 1 year ago

gaambo commented 1 year ago

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:

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:

  1. 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.
  2. 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.

Version: ACF Version: 6.0.3 WordPress Version: 6.0 PHP Version: 8.0 ACF Block-Version: 1 (via acf_register_block_type)

lgladdy commented 1 year ago

Hey @gaambo, thanks for the call out on this.

We're currently looking into how we can support this better in a back compatible way. I'll update this thread when we have more info.