Support » Plugin: WP Lightbox 2 » Bug in WordPress 5.5 – Solution provided

  • ResolvedPlugin Author csskevin

    (@csskevin)


    Hey,
    First of all, this is a great project.
    However with the new version of WordPress I have figured out an issue. The lightbox is not displayed in the new version.

    The error is caused by this code snipped in wp-lightbox-2.js of your plugin root folder:

    
    if(parseFloat($().jquery) >= 1.7){
      return $(this).on("click", onClick);
    } else {
      return $(this).live("click", onClick); //deprecated since 1.7
    }		
    

    The thing is WordPress 5.5 is using jQuery 1.12
    Due 1.12 is lower than 1.7 the script tries to use the live function, which is deprecated since 1.7, obviously.

    I would suggest to compare the jQuery version with the major and minor version.

    Here is my solution:

    
    var currentJqueryVersion = $().jquery;
    var splittedJqueryVersion = currentJqueryVersion.split(".");
    if(splittedJqueryVersion.length >= 2) {
      var majorVersion = parseInt(splittedJqueryVersion[0]);
      var minorVersion = parseInt(splittedJqueryVersion[1]);
      if(majorVersion >= 1 && minorVersion >= 7) {
        return $(this).on("click", onClick);
      } else {
        return $(this).live("click", onClick); //deprecated since 1.7
      }
    } else {
        throw new Error("jQuery version could not be determined. jQuery version: " + currentJqueryVersion);
    }
    

    Feel free to use this snippet.

    Kind regards,
    csskevin

    • This topic was modified 6 months, 3 weeks ago by csskevin.
    • This topic was modified 6 months, 3 weeks ago by csskevin.
Viewing 15 replies - 1 through 15 (of 23 total)
  • Thank you so much for providing a solution! 😀
    I love this plugin and I was sad that it stopped working.
    Your help is really appreciated!

    Guess it’s related to WP 5.5 suppressing Jquery Migrate by default..

    https://www.searchenginejournal.com/wordpress-5-5-issues/377851/

    we need to change plugin since this is not being updated since 5 years, meanwhile i applied the suggested solution, thank you!

    Plugin Author csskevin

    (@csskevin)

    Right. Especially the wp-lightbox-2.js should be rewritten. I would suggest to use a compiler like Babel for browser backwards compatibility.

    If you need help rewriting this code let me know.

    Plugin Author WP Inventory Manager

    (@chuck1982)

    @csskevin

    Can you send me an email via chuck@mrwpress.com? I’m working alongside with Syed to get access to a repo we can make changes. I’d like to see if your interested in doing the JS rewrite.

    Thanks!

    @csskevin:

    I have to replace the first code snippet you posted with the second one, right? I downloaded the wp-lightbox-2.js from my server, edited it and did so. I loaded it up again, but nothing changed: The lightbox still isn’t working.

    I’m using the latest stable WP version and version 2.28.9.2.1 of the plugin.

    Do you have an idea what could have gone wrong?

    Plugin Author csskevin

    (@csskevin)

    You need to do that for the wp-lightbox-2.js as well for the wp-lightbox-2.min.js

    If it don’t work then, open up the Javascript Console of your browser and check out if there are errors.

    @csskevin:

    Thank you, I had overseen the min.js. Now it seems to work fine again. 🙂

    roland711

    (@roland711)

    Hi,

    there is not only a “not displayed” problem. With WP Lightbox 2 active some templates (e.g. Catch Base) have bigger problems. So I have deactivated WP Lightbox 2 till a rework for the current WP is done. I am happy to see the forum and the developer is still active. So please leave here a comment when a new version is available.

    Best Regards
    Roland

    Plugin Author csskevin

    (@csskevin)

    Hey,
    Just wanted to inform, that there is now a new release (3.6.0.3) for the WP Lightbox 2 plugin.
    If there should be any issues, just let me know.

    Moderator Yui

    (@fierevere)

    ゆい

    Actually it stopped working, at least on WP 5.4.2

    wp-lightbox-2.min.js?ver=1.3.4.1:1 Uncaught ReferenceError: hide is not defined
        at wp-lightbox-2.min.js?ver=1.3.4.1:1
        at NodeList.forEach (<anonymous>)
        at a.start (wp-lightbox-2.min.js?ver=1.3.4.1:1)
        at a.onClick (wp-lightbox-2.min.js?ver=1.3.4.1:1)
    FTLRalph

    (@ftlralph)

    Can confirm, is not working at least for me with WP 5.5.1 (http://sticknodes.com/stickfigures/) – click an image thumbnail, nothing happens

    Console:

    Uncaught ReferenceError: hide is not defined
        start http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
        start http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
        onClick http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
    wp-lightbox-2.min.js:1:15555
        start http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
        forEach self-hosted:206
        start http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
        onClick http://sticknodes.com/wp-content/plugins/wp-lightbox-2/js/dist/wp-lightbox-2.min.js?ver=1.3.4.1:1
        onClick self-hosted:1208
    Plugin Author csskevin

    (@csskevin)

    Hey,
    we are aware of this issue and currently working on it. The issue happens, when you have a select box displayed on your webpage.
    We will let you know, when there is a solution for that. It shouldn’t take too long.

    @csskevin hey, any update on this? Don’t mean to be pushy just curious whats up

    Plugin Author csskevin

    (@csskevin)

    Hey @ftlralph
    The project is also available under Github: https://github.com/awesomemotive/wp-lightbox-2

    The bug fix I created is currently under review: https://github.com/awesomemotive/wp-lightbox-2/pull/2

    If the pull request has been approved and merged by the team, it will be published on WordPress.

    Thanks for your patient,
    csskevin

    hi.. how to solve this? i dont know to add this code

Viewing 15 replies - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.