From dbf9efedc9e782c70bf986d0fe17cff7415acffc Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 3 Sep 2019 12:22:47 -0400 Subject: [PATCH 01/18] Query param that causes post with Map Blocks to render as complete HTML page with nothing but the block. For AMP requests, render an iFrame with the special URL as src. --- extensions/blocks/map/map.php | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 8b8532c0e494..4f5ec3a817f1 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -25,7 +25,83 @@ function jetpack_map_block_load_assets( $attr, $content ) { $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); + if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { + global $wp, $map_block_counter; + if ( ! $map_block_counter ) { + $map_block_counter = 0; + } + $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter; + + $placeholder = preg_replace( '/(?<=%s', + esc_url( $iframe_url ), + Jetpack::get_content_width(), + Jetpack::get_content_width(), + $placeholder + ); + } + Jetpack_Gutenberg::load_assets_as_required( 'map' ); return preg_replace( '/
loadHTML( $post->post_content ); + $divs = $post_html->getElementsByTagName( 'div' ); + + $map_block_divs = array(); + foreach ( $divs as $div ) { + $classes = explode( ' ', $div->getAttribute( 'class' ) ); + if ( in_array( 'wp-block-jetpack-map', $classes, true ) ) { + $map_block_divs[] = $div; + } + } + + /* Check that we have a block matching the counter position */ + if ( ! isset( $map_block_divs[ $map_block_counter ] ) ) { + return; + } + + /* Compile scripts and styles */ + ob_start(); + + add_filter( 'jetpack_is_amp_request', '__return_false' ); + + Jetpack_Gutenberg::load_assets_as_required( 'map' ); + wp_scripts()->do_items(); + wp_styles()->do_items(); + + add_filter( 'jetpack_is_amp_request', '__return_true' ); + + $head_content = ob_get_clean(); + + /* Put together a new complete document containing only the requested block markup and the scripts/styles needed to render it */ + $block_markup = $post_html->saveHTML( $map_block_divs[ $map_block_counter ] ); + $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); + $page_html = sprintf( + '%s%s', + $head_content, + preg_replace( '/(?<= Date: Tue, 3 Sep 2019 16:38:43 -0400 Subject: [PATCH 02/18] Increment Map Block counter after render. --- extensions/blocks/map/map.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 4f5ec3a817f1..aa7711737430 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -32,6 +32,8 @@ function jetpack_map_block_load_assets( $attr, $content ) { } $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter; + $map_block_counter++; + $placeholder = preg_replace( '/(?<= Date: Tue, 3 Sep 2019 16:45:09 -0400 Subject: [PATCH 03/18] Switch to 1-based map block counter. --- extensions/blocks/map/map.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index aa7711737430..a7180107ae48 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -28,7 +28,7 @@ function jetpack_map_block_load_assets( $attr, $content ) { if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { global $wp, $map_block_counter; if ( ! $map_block_counter ) { - $map_block_counter = 0; + $map_block_counter = 1; } $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter; @@ -55,11 +55,10 @@ function jetpack_map_block_load_assets( $attr, $content ) { * Render a page containing only a single Map block. */ function jetpack_map_block_render_single_block_page() { - $map_block_counter_as_string = filter_input( INPUT_GET, 'map-block-counter', FILTER_SANITIZE_STRING ); - if ( strlen( $map_block_counter_as_string ) < 1 ) { + $map_block_counter = (int) filter_input( INPUT_GET, 'map-block-counter', FILTER_SANITIZE_NUMBER_INT ); + if ( ! $map_block_counter ) { return; } - $map_block_counter = intval( $map_block_counter_as_string ); /* Create an array of all root-level DIVs that are Map Blocks */ global $post; @@ -77,7 +76,7 @@ function jetpack_map_block_render_single_block_page() { } /* Check that we have a block matching the counter position */ - if ( ! isset( $map_block_divs[ $map_block_counter ] ) ) { + if ( ! isset( $map_block_divs[ $map_block_counter - 1 ] ) ) { return; } @@ -95,7 +94,7 @@ function jetpack_map_block_render_single_block_page() { $head_content = ob_get_clean(); /* Put together a new complete document containing only the requested block markup and the scripts/styles needed to render it */ - $block_markup = $post_html->saveHTML( $map_block_divs[ $map_block_counter ] ); + $block_markup = $post_html->saveHTML( $map_block_divs[ $map_block_counter - 1 ] ); $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); $page_html = sprintf( '%s%s', From 6123addeda87f6d5446f84250677468a128ece35 Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 3 Sep 2019 16:53:19 -0400 Subject: [PATCH 04/18] Use XPath to file Map Block instances by class. --- extensions/blocks/map/map.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index a7180107ae48..a9add10b1452 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -65,15 +65,8 @@ function jetpack_map_block_render_single_block_page() { $post_html = new DOMDocument(); $post_html->loadHTML( $post->post_content ); - $divs = $post_html->getElementsByTagName( 'div' ); - - $map_block_divs = array(); - foreach ( $divs as $div ) { - $classes = explode( ' ', $div->getAttribute( 'class' ) ); - if ( in_array( 'wp-block-jetpack-map', $classes, true ) ) { - $map_block_divs[] = $div; - } - } + $xpath = new DOMXPath( $post_html ); + $map_block_divs = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' ); /* Check that we have a block matching the counter position */ if ( ! isset( $map_block_divs[ $map_block_counter - 1 ] ) ) { From 0f0e6173d357900f1acb0894dd0dca7b473a4bbc Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 3 Sep 2019 17:23:07 -0400 Subject: [PATCH 05/18] Post ID in Map Rendering URLs. Track instances by post to enable display on non-single pages. --- extensions/blocks/map/map.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index a9add10b1452..1de7ee2889bf 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -28,11 +28,15 @@ function jetpack_map_block_load_assets( $attr, $content ) { if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { global $wp, $map_block_counter; if ( ! $map_block_counter ) { - $map_block_counter = 1; + $map_block_counter = array(); } - $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter; + $id = get_the_ID(); + if ( ! $map_block_counter[ $id ] ) { + $map_block_counter[ $id ] = 0; + } + $map_block_counter[ $id ]++; - $map_block_counter++; + $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter[ $id ] . '&map-block-post-id=' . get_the_ID(); $placeholder = preg_replace( '/(?<=loadHTML( $post->post_content ); From 35d359969a11df1155f3e9d2289c9d54d16d8fbd Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Sun, 29 Sep 2019 22:53:30 -0400 Subject: [PATCH 06/18] Map block ordinal as a static variable rather than global. --- extensions/blocks/map/map.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 1de7ee2889bf..4057a54eafc3 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -26,10 +26,9 @@ function jetpack_map_block_load_assets( $attr, $content ) { $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { - global $wp, $map_block_counter; - if ( ! $map_block_counter ) { - $map_block_counter = array(); - } + global $wp; + static $map_block_counter = []; + $id = get_the_ID(); if ( ! $map_block_counter[ $id ] ) { $map_block_counter[ $id ] = 0; From 8ca36bf8b373236919527187b06e4f628cd671fa Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 11:32:02 -0400 Subject: [PATCH 07/18] Map block sizing in AMP requests. --- extensions/blocks/map/component.js | 5 ++++- extensions/blocks/map/map.php | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/extensions/blocks/map/component.js b/extensions/blocks/map/component.js index c4ea55ae5d67..4f64ce0ef836 100644 --- a/extensions/blocks/map/component.js +++ b/extensions/blocks/map/component.js @@ -171,7 +171,10 @@ export class Map extends Component { const { map } = this.state; const mapEl = this.mapRef.current; const blockWidth = mapEl.offsetWidth; - const maxHeight = window.innerHeight * 0.8; + const maxHeight = + window.location.search.indexOf( 'map-block-counter' ) > -1 + ? window.innerHeight + : window.innerHeight * 0.8; const blockHeight = Math.min( blockWidth * ( 3 / 4 ), maxHeight ); mapEl.style.height = blockHeight + 'px'; map.resize(); diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 4057a54eafc3..2c044b25e9ec 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -39,12 +39,11 @@ function jetpack_map_block_load_assets( $attr, $content ) { $placeholder = preg_replace( '/(?<=%s', + '%s', esc_url( $iframe_url ), - Jetpack::get_content_width(), - Jetpack::get_content_width(), + absint( Jetpack::get_content_width() ), + absint( Jetpack::get_content_width() * 0.75 ), $placeholder ); } From 9fd9c0faea7580d0b0730ae0e69f7b26333890fb Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 13:11:15 -0400 Subject: [PATCH 08/18] Rework iframe URL to work correctly in the loop. --- extensions/blocks/map/map.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 2c044b25e9ec..ab5f27d2134e 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -26,7 +26,6 @@ function jetpack_map_block_load_assets( $attr, $content ) { $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { - global $wp; static $map_block_counter = []; $id = get_the_ID(); @@ -35,7 +34,13 @@ function jetpack_map_block_load_assets( $attr, $content ) { } $map_block_counter[ $id ]++; - $iframe_url = home_url( $wp->request ) . '?map-block-counter=' . $map_block_counter[ $id ] . '&map-block-post-id=' . get_the_ID(); + $iframe_url = add_query_arg( + array( + 'map-block-counter' => $map_block_counter[ get_the_ID() ], + 'map-block-post-id' => get_the_ID(), + ), + get_permalink() + ); $placeholder = preg_replace( '/(?<= Date: Tue, 1 Oct 2019 13:48:20 -0400 Subject: [PATCH 09/18] Simplified aspect ratio. --- extensions/blocks/map/map.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index ab5f27d2134e..9995c935e1e2 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -47,8 +47,8 @@ function jetpack_map_block_load_assets( $attr, $content ) { return sprintf( '%s', esc_url( $iframe_url ), - absint( Jetpack::get_content_width() ), - absint( Jetpack::get_content_width() * 0.75 ), + 4, + 3, $placeholder ); } From 48d8a536f4d35392a36e25bd6d500696952b145f Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 14:03:37 -0400 Subject: [PATCH 10/18] Slight simplification to XPath retrievasl of Map Block container. --- extensions/blocks/map/map.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 9995c935e1e2..efb6ee4f5b07 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -64,6 +64,7 @@ function jetpack_map_block_load_assets( $attr, $content ) { function jetpack_map_block_render_single_block_page() { $map_block_counter = (int) filter_input( INPUT_GET, 'map-block-counter', FILTER_SANITIZE_NUMBER_INT ); $map_block_post_id = (int) filter_input( INPUT_GET, 'map-block-post-id', FILTER_SANITIZE_NUMBER_INT ); + if ( ! $map_block_counter || ! $map_block_post_id ) { return; } @@ -73,11 +74,11 @@ function jetpack_map_block_render_single_block_page() { $post_html = new DOMDocument(); $post_html->loadHTML( $post->post_content ); - $xpath = new DOMXPath( $post_html ); - $map_block_divs = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' ); + $xpath = new DOMXPath( $post_html ); + $container = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' )->item( $map_block_counter - 1 ); /* Check that we have a block matching the counter position */ - if ( ! isset( $map_block_divs[ $map_block_counter - 1 ] ) ) { + if ( ! $container ) { return; } @@ -95,7 +96,7 @@ function jetpack_map_block_render_single_block_page() { $head_content = ob_get_clean(); /* Put together a new complete document containing only the requested block markup and the scripts/styles needed to render it */ - $block_markup = $post_html->saveHTML( $map_block_divs[ $map_block_counter - 1 ] ); + $block_markup = $post_html->saveHTML( $container ); $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); $page_html = sprintf( '%s%s', From 17e2cc7e5f73e692daa2678d3090356f73f3a91d Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 14:24:16 -0400 Subject: [PATCH 11/18] Apply the_content filter to single block page content. --- extensions/blocks/map/map.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index efb6ee4f5b07..846a04822857 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -73,7 +73,8 @@ function jetpack_map_block_render_single_block_page() { $post = get_post( $map_block_post_id ); $post_html = new DOMDocument(); - $post_html->loadHTML( $post->post_content ); + $content = apply_filters( 'the_content', $post->post_content ); + $post_html->loadHTML( $content ); $xpath = new DOMXPath( $post_html ); $container = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' )->item( $map_block_counter - 1 ); From a07566ee2e927f3781bf6522feb693dd9e3861cf Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 14:31:47 -0400 Subject: [PATCH 12/18] Suppress libxml warnings. --- extensions/blocks/map/map.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 846a04822857..c141480bb35b 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -74,7 +74,12 @@ function jetpack_map_block_render_single_block_page() { $post_html = new DOMDocument(); $content = apply_filters( 'the_content', $post->post_content ); + + /* Suppress warnings */ + libxml_use_internal_errors( true ); $post_html->loadHTML( $content ); + libxml_use_internal_errors( false ); + $xpath = new DOMXPath( $post_html ); $container = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' )->item( $map_block_counter - 1 ); From 4d44e465a6b879faaf9f6faa5d30549b9cbb8293 Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 14:34:52 -0400 Subject: [PATCH 13/18] Check for DOMDocument class. --- extensions/blocks/map/map.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index c141480bb35b..6f738266ee9e 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -72,6 +72,10 @@ function jetpack_map_block_render_single_block_page() { /* Create an array of all root-level DIVs that are Map Blocks */ $post = get_post( $map_block_post_id ); + if ( ! class_exists( 'DOMDocument' ) ) { + return; + } + $post_html = new DOMDocument(); $content = apply_filters( 'the_content', $post->post_content ); From 0733c865d11309f1f9cbc7a672586c84b73e0bba Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Tue, 1 Oct 2019 14:40:45 -0400 Subject: [PATCH 14/18] Remove filter_input, access $_GET object directly. --- extensions/blocks/map/map.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 6f738266ee9e..7693061c3f32 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -62,8 +62,10 @@ function jetpack_map_block_load_assets( $attr, $content ) { * Render a page containing only a single Map block. */ function jetpack_map_block_render_single_block_page() { - $map_block_counter = (int) filter_input( INPUT_GET, 'map-block-counter', FILTER_SANITIZE_NUMBER_INT ); - $map_block_post_id = (int) filter_input( INPUT_GET, 'map-block-post-id', FILTER_SANITIZE_NUMBER_INT ); + // phpcs:ignore WordPress.Security.NonceVerification + $map_block_counter = isset( $_GET, $_GET['map-block-counter'] ) ? absint( $_GET['map-block-counter'] ) : null; + // phpcs:ignore WordPress.Security.NonceVerification + $map_block_post_id = isset( $_GET, $_GET['map-block-post-id'] ) ? absint( $_GET['map-block-post-id'] ) : null; if ( ! $map_block_counter || ! $map_block_post_id ) { return; From 9c4d7946ff7e8265e5505a9e0b4ee4fab4d6a2fb Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Wed, 20 Nov 2019 23:45:57 -0500 Subject: [PATCH 15/18] Remove short array syntax. --- extensions/blocks/map/map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 7693061c3f32..fd6d9e197465 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -26,7 +26,7 @@ function jetpack_map_block_load_assets( $attr, $content ) { $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { - static $map_block_counter = []; + static $map_block_counter = array(); $id = get_the_ID(); if ( ! $map_block_counter[ $id ] ) { From f7d08cbb8b0b66800c64968f63f9c5f5a237bb7b Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Wed, 20 Nov 2019 23:47:33 -0500 Subject: [PATCH 16/18] Resolve PHP notice. --- extensions/blocks/map/map.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index fd6d9e197465..24a94b6d22d1 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -29,7 +29,7 @@ function jetpack_map_block_load_assets( $attr, $content ) { static $map_block_counter = array(); $id = get_the_ID(); - if ( ! $map_block_counter[ $id ] ) { + if ( ! isset( $map_block_counter[ $id ] ) ) { $map_block_counter[ $id ] = 0; } $map_block_counter[ $id ]++; From 1000d1708adbd5fe42ae0959cce456c641b71ed3 Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Wed, 20 Nov 2019 23:50:53 -0500 Subject: [PATCH 17/18] Avoid calling get_the_ID() unnecessarily, escape the counter. --- extensions/blocks/map/map.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 24a94b6d22d1..286792085682 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -36,8 +36,8 @@ function jetpack_map_block_load_assets( $attr, $content ) { $iframe_url = add_query_arg( array( - 'map-block-counter' => $map_block_counter[ get_the_ID() ], - 'map-block-post-id' => get_the_ID(), + 'map-block-counter' => absint( $map_block_counter[ $id ] ), + 'map-block-post-id' => $id, ), get_permalink() ); From d9492d1aacd8bcc271d3fb0c1a6f85e6663d87f3 Mon Sep 17 00:00:00 2001 From: Jefferson Rabb Date: Wed, 20 Nov 2019 23:53:03 -0500 Subject: [PATCH 18/18] Comment for the_content filter. Pass post_html by reference to libxml. --- extensions/blocks/map/map.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/blocks/map/map.php b/extensions/blocks/map/map.php index 286792085682..d0c82a0d7c2b 100644 --- a/extensions/blocks/map/map.php +++ b/extensions/blocks/map/map.php @@ -79,11 +79,12 @@ function jetpack_map_block_render_single_block_page() { } $post_html = new DOMDocument(); - $content = apply_filters( 'the_content', $post->post_content ); + /** This filter is already documented in core/wp-includes/post-template.php */ + $content = apply_filters( 'the_content', $post->post_content ); /* Suppress warnings */ libxml_use_internal_errors( true ); - $post_html->loadHTML( $content ); + @$post_html->loadHTML( $content ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged libxml_use_internal_errors( false ); $xpath = new DOMXPath( $post_html );