diff --git a/includes/embeds/class-amp-facebook-embed-handler.php b/includes/embeds/class-amp-facebook-embed-handler.php
index c72072b842f..8fed0df497d 100644
--- a/includes/embeds/class-amp-facebook-embed-handler.php
+++ b/includes/embeds/class-amp-facebook-embed-handler.php
@@ -49,29 +49,19 @@ public function unregister_embed() {
}
/**
- * Sanitized
tags to
.
+ * Sanitize raw embeds.
*
* @param Document $dom DOM.
*/
public function sanitize_raw_embeds( Document $dom ) {
- $nodes = $dom->getElementsByTagName( $this->sanitize_tag );
- $num_nodes = $nodes->length;
+ $replaced = 0;
- if ( 0 === $num_nodes ) {
- return;
- }
+ $replaced += $this->sanitize_raw_embed_divs( $dom );
- for ( $i = $num_nodes - 1; $i >= 0; $i-- ) {
- $node = $nodes->item( $i );
- if ( ! $node instanceof DOMElement ) {
- continue;
- }
-
- $embed_type = $this->get_embed_type( $node );
+ $replaced += $this->sanitize_raw_embed_fb_components( $dom );
- if ( null !== $embed_type ) {
- $this->create_amp_facebook_and_replace_node( $dom, $node, $embed_type );
- }
+ if ( 0 === $replaced ) {
+ return;
}
/*
@@ -100,6 +90,65 @@ public function sanitize_raw_embeds( Document $dom ) {
}
}
+ /**
+ * Sanitize tags to
.
+ *
+ * @param Document $dom DOM.
+ * @return int Replacements made.
+ */
+ private function sanitize_raw_embed_divs( Document $dom ) {
+ $replaced = 0;
+ $nodes = $dom->getElementsByTagName( $this->sanitize_tag );
+ $num_nodes = $nodes->length;
+
+ if ( 0 === $num_nodes ) {
+ return 0;
+ }
+
+ for ( $i = $num_nodes - 1; $i >= 0; $i-- ) {
+ $node = $nodes->item( $i );
+ if ( ! $node instanceof DOMElement ) {
+ continue;
+ }
+
+ $embed_type = $this->get_embed_type( $node );
+
+ if ( null !== $embed_type ) {
+ $this->create_amp_facebook_and_replace_node( $dom, $node, $embed_type );
+ $replaced++;
+ }
+ }
+ return $replaced;
+ }
+
+ /**
+ * Sanitize tags to .
+ *
+ * @param Document $dom DOM.
+ * @return int Replacements made.
+ */
+ private function sanitize_raw_embed_fb_components( Document $dom ) {
+ $replaced = 0;
+ $nodes = $dom->getElementsByTagName( 'post' );
+ $num_nodes = $nodes->length;
+
+ if ( 0 === $num_nodes ) {
+ return 0;
+ }
+
+ for ( $i = $num_nodes - 1; $i >= 0; $i-- ) {
+ $node = $nodes->item( $i );
+ if ( ! $node instanceof DOMElement ) {
+ continue;
+ }
+
+ $embed_type = 'post';
+ $this->create_amp_facebook_and_replace_node( $dom, $node, $embed_type );
+ $replaced++;
+ }
+ return $replaced;
+ }
+
/**
* Get embed type.
*