AdvancedCustomFields / AdvancedCustomFields/acf
Update ACF blocks via block API dosen't work as expected
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Hey @lgladdy,
lately I've been learning more about the WordPress Block Editor API. There are many useful functions that we can use to interact with blocks. I noticed that using the updateBlockAttributes() function applied to ACF blocks does not work as expected.
wp.data.dispatch('core/block-editor').updateBlockAttributes(clientId, {
data: { ... },
});
or
wp.data.dispatch('core/block-editor').updateBlock(clientId, {
attributes: {
data: {
field_name: 'field_value'
}
}
} );
What works is that after updating the ACF block attributes in the above way, the block is updated with the newly set attributes. It seems render_block_preview gets the job done after swapping the block attributes.
But the BlockForm in the sidebar contains the old settings. That means, if I change a field after updating the block in the above way, the updated block reverts to the original state.
The behavior is understandable as the BlockForm was not updated when the Block was updated via the API. Unfortunately, this causes updating the block not to work that way.
Ultimately, only the BlockForm would have to be updated. Is it possible for ACF to update the BlockForm as well?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with WordPress Block Editor API calls to update an ACF block, then inspect how render_block_preview and the sidebar BlockForm handle the block attributes. Done means API updates are reflected in the BlockForm and later field edits no longer revert those changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, wordpress
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100