In my code I use the following function to register my ACF blocks:
acf_register_block_type($args);
$args in this case is an array based on a .json file. I like using this function because with this I am able to modify the array as I like it (e.g. translating title and description).
I also have the following code in my array:
"attributes": {
"style": {
"type": "object",
"default": {
"color": {
"background": "var(--wp--preset--color--button-primary-initial-background)"
},
"spacing": {
"margin": {
"top" : "var(--wp--preset--spacing--30)"
}
}
}
}
},
But I found out that the “style” attribute is ‘removed’ (read: not added) by the ACF plugin whenever I use acf_register_block_type(). After some digging I found a function called acf_get_block_type_default_attributes() in the file /advanced-custom-fields-pro/pro/blocks.php on line 310 that completely replaced the ‘attributes’ of my original array.
Unfortunately this function does not contain any hooks (actions/filters) to modify this array. How can I still get the attribute ‘style’ to work with acf_register_block_type()?