serialize_blocks breaking html tags in content
I'm trying to inject some data into blocks via PHP but am running into trouble with parse_blocks/serialize_blocks breaking my content
I'm using the default 2020 theme and have no plugins installed
add_action('wp', function() {
$oPost = get_post(119);
printf(h1Post Content/h1p%s/p, var_dump($oPost-post_content));
$aBlocks = parse_blocks($oPost-post_content);
printf(h1Parsed Blocks/h1pre%s/pre, print_r($aBlocks, true));
$sSerialisedBlocks = serialize_blocks($aBlocks);
printf(h1Serialised Blocks/h1p%s/p, var_dump($sSerialisedBlocks));
}, PHP_INT_MAX);
The first print (just outputting the post content) contains this text...
h3What types of accommodation are available in xxxx?\/h3
The second (after parsing into blocks) contains this...
h3What types of accommodation are available in xxxx?/h3
But after re-serialising the blocks I get this...
\u003ch3\u003eWhat types of accommodation are available in xxxx?\u003c\/h3\u003e
Could someone tell me what I'm doing wrong?
EDIT
Ok so I followed the source code for serialize_blocks and it does seem like this is intentional with serialize_block_attributes explicitly converting some characters
My question is why then are these characters showing up in the WYSIWYG instead of being correctly converted back?
Topic block-editor html-editor Wordpress
Category Web