diff --git a/includes/sanitizers/class-amp-gallery-block-sanitizer.php b/includes/sanitizers/class-amp-gallery-block-sanitizer.php index 95a5a7e6979..9e85e489b09 100644 --- a/includes/sanitizers/class-amp-gallery-block-sanitizer.php +++ b/includes/sanitizers/class-amp-gallery-block-sanitizer.php @@ -114,8 +114,11 @@ public function sanitize() { */ protected function get_caption_element( DOMElement $img_element ) { $figcaption_element = null; - - if ( isset( $img_element->nextSibling->nodeName ) && Tag::FIGCAPTION === $img_element->nextSibling->nodeName ) { + if ( + isset( $img_element->nextSibling->nodeName ) + && $img_element->nextSibling instanceof DOMElement + && Tag::FIGCAPTION === $img_element->nextSibling->nodeName + ) { $figcaption_element = $img_element->nextSibling; } @@ -123,6 +126,7 @@ protected function get_caption_element( DOMElement $img_element ) { if ( ! $figcaption_element && isset( $img_element->parentNode->nextSibling->nodeName ) + && $img_element->parentNode->nextSibling instanceof DOMElement && Tag::FIGCAPTION === $img_element->parentNode->nextSibling->nodeName ) { $figcaption_element = $img_element->parentNode->nextSibling; diff --git a/includes/sanitizers/class-amp-o2-player-sanitizer.php b/includes/sanitizers/class-amp-o2-player-sanitizer.php index 3195fd7418a..8ec0c4a8a34 100644 --- a/includes/sanitizers/class-amp-o2-player-sanitizer.php +++ b/includes/sanitizers/class-amp-o2-player-sanitizer.php @@ -108,7 +108,7 @@ private function create_amp_o2_player( Document $dom, DOMElement $node ) { $parent_node = $node->parentNode; // Remove the ID from the original node so that PHP DOM doesn't fail to set it on the replacement element. - if ( $parent_node->hasAttribute( Attribute::ID ) ) { + if ( $parent_node instanceof DOMElement && $parent_node->hasAttribute( Attribute::ID ) ) { $component_attributes['id'] = $parent_node->getAttribute( Attribute::ID ); $parent_node->removeAttribute( Attribute::ID ); }