Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12440
    stefanfis
    Participant

    I’ve got a post with several WordPress galleries. Now, in some of them the data-rel=”lightbox-gallery-N” attribute is missing. The galleries are created by the default WordPress editor without any modifications on our side. I can’t see any pattern where it is missing though. There is one gallery, where just one out of six images misses the data-rel attribute. In another gallery, it’s two out of four.

    This is how the shortcode within the post looks like:
    [gallery link="file" columns="1" size="medium" ids="1,2,3,4"]

    That’s one of the links that are correct:
    <a title="some title" href="image.jpg" data-rel="lightbox-gallery-3"><img width="203" height="300" src="image.jpg" class="attachment-medium size-medium" alt="some alt" aria-describedby="gallery-3-16459" srcset="image.jpg 203w, image.jpg 768w, image.jpg 694w, image.jpg 1323w" sizes="(max-width: 203px) 100vw, 203px"></a>

    Wordpress: 4.5.3
    Responsive Lightbox: 1.6.8

    #12441
    stefanfis
    Participant

    I’ve found the error. There were line breaks in the image title, they have been pasted from the original source into the WordPress image description field by our editors.

    In class-frontend.php (function add_gallery_lightbox_selector) in line 150 (in version 1.6.8) is the code where the data-rel attribute gets inserted into the $link markup. But the preg_match-functions expect a single line, while the $title variable inserts a line break into the markup. I’ve patched the code to match as single lines by introducing a ‘s’ modifier to the regex.

    original:
    $link = ( preg_match( '/<a.*? (?:data-rel)=("|\').*?("|\')>/', $link ) === 1 ? preg_replace( '/(<a.*? data-rel=(?:"|\').*?)((?:"|\').*?>)/', '$1 ' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '$2', $link ) : preg_replace( '/(<a.*?)>/', '$1 data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '">', $link ) );

    patched:
    $link = ( preg_match( '/<a.*? (?:data-rel)=("|\').*?("|\')>/s', $link ) === 1 ? preg_replace( '/(<a.*? data-rel=(?:"|\').*?)((?:"|\').*?>)/s', '$1 ' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '$2', $link ) : preg_replace( '/(<a.*?)>/s', '$1 data-rel="' . Responsive_Lightbox()->options['settings']['selector'] . '-gallery-' . $this->gallery_no . '">', $link ) );

    This seems to work so far without problems. Perhaps you could test this modifications and introduce it in your next release.

    #12511
    Bartosz
    Keymaster

    Thanks @stefanfis, we’ll have a look into this.

    #12530
    Bartosz
    Keymaster

    You’re right – we’ll include the fix in the next release. Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.