I am writing a migration script which has to read the post_content of posts and then dynamically change some attributes of some custom Gutenberg blocks.
I was able to read the post_content and then convert them into block objects by using the parse_blocks
function. I was also able to dynamically change the attributes of the custom blocks by manipulating the block objects.
But I am not able to convert these block objects into the special HTML comments that Gutenberg uses to serialize them so that I can update the post_content.
I found that the PHP part of WordPress core only has parse_blocks
function to parse the special HTML comments into block objects and render_block
function to render the blocks, but there is no serialize_block
function.
I found that in JavaScript there is a function called serializeBlock
which does this. But is there an equivalent of it in PHP which I can call from my migration scripts?