contentPreRender function conflict with theme.json
-
Hello, I discovered an issue with your
contentPreRender($block)
(Function to load assets for post/page on front-end before gutenberg rendering)
. The function does not play well with block attributes defined bytheme.json
files.The problem is that when you filter blocks that are not being styled by your plugin, you only use the
['innerContent']
portion of the block data. (See line #3580 ofadvanced-gutenberg-main.php
–array_push($block['innerContent'], $style);
)So when one attempts to use link-color settings from
theme.json
such as these:{ "version": 2, "settings": { "color": { "link": true, "palette": [ { "name": "Green", "slug": "green", "color": "#78be20" } ] } } }
– the resulting block data that is used by WordPress to link their inline style to the block requires the attributes portion of the data, which is not contained in the
innerContent
, see below for sample data (simplified for readability):[ 'blockName' => 'core/paragraph', 'attrs' => [ 'style' => [ 'elements' => [ 'link' => [ 'color' => [ 'text' => 'var:preset|color|green', ], ], ], ], ], 'innerBlocks' => [], 'innerHTML' => '<p class="has-link-color">This line has a link <a href="#">colored green</a>.</p>', 'innerContent' => [ 0 => '<p class="has-link-color">This line has a link <a href="#">colored green</a>.</p>', ], ]
Hopefully there is a way to better integrate with block data outside of the
innerContent
– however, commenting out line #3580 seems to fix the conflict for now.Thank you, looking forward to see if you can fix this easily!
- The topic ‘contentPreRender function conflict with theme.json’ is closed to new replies.