Skip to content

Commit

Permalink
Block Supports: Avoid PHP warnings on libxml < 2.7.8
Browse files Browse the repository at this point in the history
Only specifies `LIBXML_HTML_NODEFDTD` when defined.

Fix ported from the AMP WordPress Plugin:
https://github.com/ampproject/amp-wp/pull/4486/files

Props @schlessera.
See WordPress#25122.
  • Loading branch information
getsource committed Oct 16, 2020
1 parent ae80d5d commit 536a325
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/block-supports/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ function gutenberg_apply_block_supports( $block_content, $block ) {
. $block_content
. '</body></html>';

$success = $dom->loadHTML( $wrapped_block_html, LIBXML_HTML_NODEFDTD | LIBXML_COMPACT );
$options = LIBXML_COMPACT;

// LIBXML_HTML_NODEFDTD is only available in libxml 2.7.8+.
if ( defined( 'LIBXML_HTML_NODEFDTD' ) ) {
$options |= constant( 'LIBXML_HTML_NODEFDTD' );
}
$success = $dom->loadHTML( $wrapped_block_html, $options );

// Clear errors and reset the use_errors setting.
libxml_clear_errors();
Expand Down

0 comments on commit 536a325

Please sign in to comment.