Consent Area Block does not work with nested blocks
-
Hello,
I am integrating the Consent Area Block into a page with Gutenberg blocks. I have my sections grouped using the group block. Whenever I accept the cookies, the content is not shown. It works perfectly fine when the block is at the root level of the block structure.
Here’s a simple page with a grouped Consent Area Block to replicate the issue:
<!-- wp:group {"layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:complianz/consent-area {"blockId":"dt6uy","postId":161,"placeholderContent":"\u003cdiv class=\u0022cmplz-consent-block\u0022\u003e \n\u003cspan class=\u0022cmplz-consent-block-title\u0022\u003eWhat is HSTS HTTP Strict Transport Security Really Simple SSL\u003c/span\u003e\n\u003cp class=\u0022cmplz-consent-block-text\u0022\u003eBefore watching the video how to leverage SSL with HSTS, please accept YouTube cookies.\u003c/p\u003e\n\u003cdiv class=\u0022cmplz-consent-block-actions\u0022\u003e \n\u003cbutton class=\u0022cmplz-consent-block-button\u0022\u003eAccept\u003c/button\u003e \n\u003ca href=\u0022/cookie-policy\u0022 class=\u0022cmplz-consent-block-link\u0022\u003eWhich YouTube Cookies?\u003c/a\u003e\n\u003c/div\u003e\n\u003c/div\u003e","consentedContent":"\u003cp\u003eContent to show when cookies are accepted.\u003c/p\u003e"} /--></div>
<!-- /wp:group -->I dove into the plugin’s code and saw that the issue is the
cmplz_rest_consented_contentfunction inrest-api/rest-api.php. If your replace the foreach on line 74 with this code$blockOutput = cmplz_rest_consented_content_find_block($blocks, $block_id);
if ($blockOutput !== null) {
$output = $blockOutput;
}and add this new function
function cmplz_rest_consented_content_find_block(array $blocks, string $block_id): string|null
{
foreach ($blocks as $block) {
if ($block['blockName'] === 'complianz/consent-area' && $block['attrs']['blockId'] === $block_id) {
return $block['attrs']['consentedContent'];
}
if (isset($block['innerBlocks']) && !empty($block['innerBlocks'])) {
$output = cmplz_rest_consented_content_find_block($block['innerBlocks'], $block_id);
if ($output !== null) {
return $output;
}
}
}
return null;
}it should work for nested groups as well.
You must be logged in to reply to this topic.