From 1eb542e7faa4ecf77ed78cc24f3aab5b324ce038 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 30 May 2018 22:29:06 -0700 Subject: [PATCH] Fix adding images to AMP carousel gallery --- .../class-amp-gallery-block-sanitizer.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/includes/sanitizers/class-amp-gallery-block-sanitizer.php b/includes/sanitizers/class-amp-gallery-block-sanitizer.php index 09b753d2625..07ba6c6ffbd 100644 --- a/includes/sanitizers/class-amp-gallery-block-sanitizer.php +++ b/includes/sanitizers/class-amp-gallery-block-sanitizer.php @@ -97,20 +97,24 @@ public function sanitize() { continue; } - $images = null; + $images = array(); // If it's not AMP lightbox, look for links first. if ( ! $is_amp_lightbox ) { - $images = $node->getElementsByTagName( 'a' ); + foreach ( $node->getElementsByTagName( 'a' ) as $element ) { + $images[] = $element; + } } // If not linking to anything then look for . - if ( ! $images || 0 === $images->length ) { - $images = $node->getElementsByTagName( 'amp-img' ); + if ( empty( $images ) ) { + foreach ( $node->getElementsByTagName( 'amp-img' ) as $element ) { + $images[] = $element; + } } // Skip if no images found. - if ( ! $images || 0 === $images->length ) { + if ( empty( $images ) ) { continue; }