From c899c451e8cbe333826b816a8efcbd8b7f8fa91d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 15 Jun 2023 14:54:21 +0530 Subject: [PATCH 1/6] Update element string with Tag::P constant --- includes/embeds/class-amp-base-embed-handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/embeds/class-amp-base-embed-handler.php b/includes/embeds/class-amp-base-embed-handler.php index ee18eba26b8..d1811f81f3d 100644 --- a/includes/embeds/class-amp-base-embed-handler.php +++ b/includes/embeds/class-amp-base-embed-handler.php @@ -150,7 +150,7 @@ protected function unwrap_p_element( DOMElement $node ) { if ( $parent_node instanceof DOMElement && - 'p' === $parent_node->tagName + Tag::P === $parent_node->tagName && false === $parent_node->hasAttributes() && From 0ffcc8807ecf20509c91dbe8fac9984da0c56eb4 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 15 Jun 2023 15:06:27 +0530 Subject: [PATCH 2/6] Add `::unwrap_p_element_by_child_tag_name()` method --- .../embeds/class-amp-base-embed-handler.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/embeds/class-amp-base-embed-handler.php b/includes/embeds/class-amp-base-embed-handler.php index d1811f81f3d..6e5768218cc 100644 --- a/includes/embeds/class-amp-base-embed-handler.php +++ b/includes/embeds/class-amp-base-embed-handler.php @@ -160,6 +160,24 @@ protected function unwrap_p_element( DOMElement $node ) { } } + /** + * Unwrap `

` element based on passed child tag name. + * + * @since 2.4.2 + * + * @param Document $dom Document. + * @param string $child_tag_name Child tag name. + */ + protected function unwrap_p_element_by_child_tag_name( $dom, $child_tag_name ) { + $nodes = $dom->xpath->query( "//p/{$child_tag_name}" ); + + if ( $nodes->length && $nodes instanceof DOMNodeList ) { + foreach ( $nodes as $node ) { + $this->unwrap_p_element( $node ); + } + } + } + /** * Removes the node's nearest `