acf-extended / ACF-Extended

🚀 All-in-one enhancement suite that improves WordPress & Advanced Custom Fields
https://www.acf-extended.com
238 stars 27 forks source link

Render callback for blocks formats block data array differently if the request is for the WP previewer #51

Closed noknokcody closed 4 years ago

noknokcody commented 4 years ago

Describe the bug I'm not entirely sure if this is related to ACF Pro or ACF Extended but it appears that when setting up a block render callback that data passed to that callback is in an entirely different format when the render callback request is called via the block previewed (Ajax).

Here's what the data object looks like when my custom block is rendered on the front-end or when the previewed is loading:

Preview data

Here's what the data object looks like when a block is rendered via ajax (After updating block settings in the previewer):

Ajax preview data

To Reproduce

  1. Create a custom block with a few custom fields
  2. Attach debugger to the callback function
  3. Load block into Gutenberg editor
  4. Setup block an enter data into custom fields
  5. Preview block on the frontend using debugger (1st screenshot)
  6. Update block settings on the backend and load new preview via ajax (2nd screenshot)

Expected behavior I'd expect that the data passed to the callback function would be in the same kind-of format regardless of how the block is being loaded

WordPress & ACF WordPress version: 4.2.2 ACF Pro version: 5.8.6 ACF add-ons: none

noknokcody commented 4 years ago

Just realized that I'm supposed to get block data via get_field() not the actual data field on the block array.

Never forget that you can save mere minutes of "reading the manual" though hours of "quick debugging".