Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for filtering of gallery 'link' attribute #3439

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions includes/embeds/class-amp-gallery-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ public function maybe_override_gallery( $html, $attributes ) {
return $attr;
};

$set_link_attribute = static function ( $attributes ) {
$attributes['link'] = 'none';
return $attributes;
};

remove_filter( 'post_gallery', [ $this, 'maybe_override_gallery' ], 10 );
add_filter( 'wp_get_attachment_image_attributes', $add_lightbox_attribute );
add_filter( 'shortcode_atts_gallery', $set_link_attribute, PHP_INT_MAX );

$attributes['link'] = 'none';
$html = gallery_shortcode( $attributes );
$html = gallery_shortcode( $attributes );
Comment on lines -177 to +183
Copy link
Contributor Author

@kienstra kienstra Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When gallery_shortcode() runs, it's possible to filter the $attributes with the shortcode_atts_gallery filter.

And that can change the previous value of $attributes['link'] = 'none';, causing the lightbox to not work.


remove_filter( 'wp_get_attachment_image_attributes', $add_lightbox_attribute );
add_filter( 'post_gallery', [ $this, 'maybe_override_gallery' ], 10, 2 );
remove_filter( 'shortcode_atts_gallery', $set_link_attribute, PHP_INT_MAX );
}

return $html;
Expand Down