I am having a very similar issue, except for me the Content Display
block was missing, others were fine.
Turns out that the var advgb_blocks_vars = {
line that should contain a JSON under the original_settings.styles
array had an object, who’s css
property was not a css, but an HTML. Being so escaping somehow failed, so eventually this variable as well as subsequent variables, including advgbBlocks
were never set on the editor screens.
Indeed the CSS ended up being an HTML because a CSS file was not where it was supposed to be, which ended up resulting in the WordPress 404 HTML. I’ve added < !-- < ?= $ _SERVER['REQUEST_URI'] ?> -->
to the top of the head of my theme to find out the missing CSS file.
Eliminating the wrong CSS enqueuing fixed the issue.
On one hand I’ve written it in hope that it may help others facing similar issues.
But on the other hand I’m wondering how it is possible? AdvancedGutenbergMain::$original_block_editor_setting
is added to the page using the standard wp_localize_script
. How come escaping breaks when one of the array members end up being an HTML instead of CSS? It is supposed to go through json_encode
so it shouldn’t matter. Still, the JSON is broken…
So looking into it more, turns out WordPress is quite naive when encoding json in the localize script call calling wp_json_encode
without any options, which in turn calls PHP json_encode
without options. Adding JSON_HEX_TAG
to the call fixes the broken JSON and thus the missing PublishPress blocks issue as well.
UPDATE: So it turns out the issue is caused by another plugin which injects CSS files using non standard method, that is it buffers all HTML output, then searches for </head>
and adds it’s style links before that tag. Since the inline JS object created by wp_localize_script
contains the token </head>
due to a whole 404 HTML is included instead of a CSS, now this script finds that tag, and injects it’s <style...
tag before. However indeed this tag contains a "
which closes the JSON string and breaks the object structure. The only reason adding JSON_HEX_TAG
“fixed” the issue, is that </head>
became \u003C/head\u003E
which was now immune to that non standard behaviour.
This being said, my issue might have been a different one than OPs, but in may be related. My takeaway: If PublishPress blocks are missing, check the console for Uncaught SyntaxError: missing }
and Uncaught ReferenceError: advgbBlocks is not defined
errors, as it may point into the direction of solution.