Skip to content

Commit 57b280c

Browse files
committed
Simplify unwrap_p_element logic
1 parent 92a1c32 commit 57b280c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

includes/embeds/class-amp-base-embed-handler.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,27 @@ static function ( DOMNode $child ) {
128128
}
129129

130130
/**
131-
* Replace the node's parent with itself if the parent is a <p> tag, has no attributes and has no other children.
131+
* Replace an element's parent with itself if the parent is a <p> tag which has no attributes and has no other children.
132+
*
132133
* This usually happens while `wpautop()` processes the element.
133134
*
134135
* @since 2.0.6
136+
* @see AMP_Tag_And_Attribute_Sanitizer::remove_node()
135137
*
136138
* @param DOMElement $node Node.
137139
*/
138140
protected function unwrap_p_element( DOMElement $node ) {
139141
$parent_node = $node->parentNode;
140-
141-
if ( $parent_node instanceof DOMElement && 'p' === $parent_node->tagName && false === $parent_node->hasAttributes() ) {
142-
$child_element_count = count( $this->get_child_elements( $parent_node ) );
143-
if ( 1 === $child_element_count ) {
144-
$parent_node->parentNode->replaceChild( $node, $parent_node );
145-
}
142+
if (
143+
$parent_node instanceof DOMElement
144+
&&
145+
'p' === $parent_node->tagName
146+
&&
147+
false === $parent_node->hasAttributes()
148+
&&
149+
1 === count( $this->get_child_elements( $parent_node ) )
150+
) {
151+
$parent_node->parentNode->replaceChild( $node, $parent_node );
146152
}
147153
}
148154
}

0 commit comments

Comments
 (0)