Skip to content

Commit

Permalink
check if inner block is stackable/heading, escape variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed Sep 24, 2023
1 parent 902f998 commit b32981b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/block/accordion/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ public function render_block_accordion_faq_schema( $block_content, $block ) {
if ( isset( $attributes[ 'enableFAQ' ] ) && $attributes[ 'enableFAQ' ] ) {
// innerBlocks[0] is for the title
// retrieve stackable/column -> stackable/icon-label -> stackable/heading
$question = trim( strip_tags( $block[ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerHTML' ] ) );
$isHeadingBlock = $block[ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'blockName' ] === 'stackable/heading';
$question = '';
if ( $isHeadingBlock ) {
$question = trim( strip_tags( $block[ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerHTML' ] ) );
} else {
$question = trim( strip_tags( $block[ 'innerBlocks' ][0][ 'innerBlocks' ][0][ 'innerBlocks' ][1][ 'innerHTML' ] ) );
}

// innerBlocks[1] is for the content
// content may have multiple blocks so we need to retrieve all texts from each block
Expand All @@ -123,10 +129,10 @@ public function render_block_accordion_faq_schema( $block_content, $block ) {

$this->faq_entities[] = '{
"@type": "Question",
"name": "' . $question . '",
"name": ' . json_encode( $question ) . ',
"acceptedAnswer": {
"@type": "Answer",
"text": \'' . $answer .'\'
"text": ' . json_encode( $answer ) .'
}
}';
}
Expand Down

0 comments on commit b32981b

Please sign in to comment.