Skip to content

Commit

Permalink
#1400 remove http/https from amp-audio and amp-video URLs to avoid va…
Browse files Browse the repository at this point in the history
…lidation issues
  • Loading branch information
MARQAS committed Jan 3, 2019
1 parent 92dd4aa commit 4bda2c9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions templates/features.php
Expand Up @@ -2432,6 +2432,29 @@ function ampforwp_modified_search_sidebar( $content ) {
$element->setAttribute('target', '_top');
}
}
// Remove http/https from Audio and Video URLs #1400
$video_nodes = $dom->getElementsByTagName( 'amp-video' );
$num_nodes = $video_nodes->length;
if ( 0 !== $num_nodes ) {
for ( $i = 0; $i < $video_nodes->length; ++$i ) {
$element = $video_nodes->item( $i );
$source = $element->childNodes->item(0);
$source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') ));
$source = $element->childNodes->item(1);
$source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') ));
}
}
$audio = $dom->getElementsByTagName( 'amp-audio' );
$num_nodes = $audio->length;
if ( 0 !== $num_nodes ) {
for ( $i = 0; $i < $audio->length; ++$i ) {
$element = $audio->item( $i );
$source = $element->childNodes->item(0);
$source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') ));
$source = $element->childNodes->item(1);
$source->setAttribute('src',preg_replace('#^http?:#', '', $source->getAttribute('src') ));
}
}
$content = AMP_DOM_Utils::get_content_from_dom($dom);
return $content;
}
Expand Down

0 comments on commit 4bda2c9

Please sign in to comment.