Skip to content

Commit

Permalink
reverted the code for validating HTML (resolves #307)
Browse files Browse the repository at this point in the history
  • Loading branch information
nk-o committed Mar 21, 2024
1 parent 755bb97 commit 368d86b
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions classes/class-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,42 +239,12 @@ public function get_block( $request ) {
$block_result = lazyblocks()->blocks()->render_callback( $block_attributes, null, $block_context, $block );

if ( isset( $block_result ) && null !== $block_result ) {
if ( ! $this->is_valid_html( $block_result ) ) {
return $this->error( 'lazy_block_invalid', esc_html__( 'Please ensure that the output is a valid HTML structure.', 'lazy-blocks' ) );
}

return $this->success( $block_result );
} else {
return $this->error( 'lazy_block_no_render_callback', esc_html__( 'Render callback is not specified.', 'lazy-blocks' ) );
}
}

/**
* Check HTML valid.
*
* @param string $html - Layout of the current block.
* @return boolean
*/
public function is_valid_html( $html ) {
// Remove <InnerBlocks> tags using regular expression.
$cleaned_html = preg_replace( '/<InnerBlocks([\S\s]*?)\/>/', '', $html );

$dom = new DOMDocument();

// Disable libxml errors and error handling.
libxml_use_internal_errors( true );

$dom->loadHTML( $cleaned_html );

// Get any errors from libxml.
$errors = libxml_get_errors();

// Clear libxml error buffer.
libxml_clear_errors();

return empty( $errors );
}

/**
* Update block data.
*
Expand Down

0 comments on commit 368d86b

Please sign in to comment.