Skip to content

Commit

Permalink
Use Weston's method of finding if the link is to a file
Browse files Browse the repository at this point in the history
Use the line that Weston suggested,
instead of attachment_url_to_postid().
  • Loading branch information
kienstra committed Oct 18, 2019
1 parent d243326 commit 783a8d8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions includes/sanitizers/class-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,13 @@ private function maybe_add_lightbox_attributes( $attributes, $node ) {
return $attributes;
}

// This should be true for links to the actual media file, but not for links to the attachment page.
$is_file_url = preg_match( '/\.\w+$/', wp_parse_url( $parent_node->getAttribute( 'href' ), PHP_URL_PATH ) );
$is_node_wrapped_in_media_file_link = (
'a' === $parent_node->tagName
&&
( 'figure' === $parent_node->tagName || 'figure' === $parent_node->parentNode->tagName )
&&
attachment_url_to_postid( $parent_node->getAttribute( 'href' ) )
$is_file_url // This should be a link to the media file, not the attachment page.
);

if ( 'figure' !== $parent_node->tagName && ! $is_node_wrapped_in_media_file_link ) {
Expand Down

0 comments on commit 783a8d8

Please sign in to comment.