-1

I am using the Simplelightbox plugin (Plugin URL or Homepage URL) on my site: http://joshrodg.com/condos/pictures/

On that page I have a picture gallery that is using the Lightbox and then right below the picture gallery, there is a section called Pictures with 5 thumbnails, this section is also using the Lightbox.

There are 14 images in the picture gallery and 5 images in the Picture section (underneath the gallery).

Out of the box, when you click on an image the Lightbox would open, but the total would say 1 of 19, because there are 19 total images using the lightbox plugin on that page.

What I wanted it to do was separate those sections, or have multiple lightboxes. So, 1 of 14 would show when clicking on a gallery image or 1 of 5 would show when clicking on a thumbnail in the pictures section.

I was able to fix this by modifying the following file (because there wasn't a plugin option that would allow me to configure the multiple Lightboxes): http://joshrodg.com/condos/wp-content/plugins/simplelightbox/resources/js/setup.simplelightbox.js

The original code (starts at line 35):

if($('a.simplelightbox ').length ) {
    var simplelightbox = $("a.simplelightbox").simpleLightbox(options);
}

The modified code (starts at line 35):

if($('a.simplelightbox ').length ) {
    var lightbox1 = $('.gallery a').simpleLightbox();
    var lightbox2 = $('#pict a').simpleLightbox();
}

This fixed the problem, but the next time the plugin has an update, those settings may get wiped away.

Could someone share a function or something that I could use in my template to avoid a possible issue if the plugin was ever updated?

Thanks,
Josh

  • 1
    if the plugin automatically creates instances of the lightbox when it finds the simplelightbox class, just don't give those links that class, then you can create the lightbox instances yourself in your own js file. – Milo Feb 10 '17 at 20:07
  • you should not modify plugins in ways which are not explicitly endorsed by the plugin author – Mark Kaplun Feb 11 '17 at 19:39
  • I agree, I have e-mailed the plugin author directly. I hope he includes support for this feature natively down the road. – Josh Rodgers Feb 12 '17 at 1:31
1

Create a plugin that dequeues the javascript you don't want, and enqueues the edited javascript.

<?php
/**
 * Plugin Name: Stackexchange Sample
 * Author: Nathan Johnson
 * Licence: GPL2+
 * Licence URI: https://www.gnu.org/licenses/gpl-2.0.en.html
 * Domain Path: /languages
 * Text Domain: stackexchange-sample
 */

//* Don't access this file directly
defined( 'ABSPATH' ) or die();

add_action( 'wp_enqueue_scripts', 'wpse_106269_enqueue_scripts', 15 );
function wpse_106269_enqueue_scripts() {
  $slb = SimpleLightbox::get_instance();
  wp_dequeue_script( 'simplelightbox-call');
  wp_deregister_script( 'simplelightbox-call' );

  wp_register_script( 'simplelightbox-edit',
    plugins_url( '/simplelightbox-edit.js', __FILE__ ),
    [ 'jquery', 'simplelightbox' ], false, true);
  wp_localize_script( 'simplelightbox-edit', 'php_vars', $slb->options );
  wp_enqueue_script( 'simplelightbox-edit' );
}

EDIT: I just tested the above plugin on a fresh install and it dequeues the 'simplelightbox-call' javascript and enqueues the edited script.

  • This look interesting, exploring this one right now :-) Thank you for the suggestion! – Josh Rodgers Feb 11 '17 at 17:13
  • I tried this: jsfiddle.net/2jjLwb9z, but it looks like the plugin is still loading the original setup.simplelightbox.js file. – Josh Rodgers Feb 11 '17 at 18:01
  • Thank you for working on this, I got it working!! I had one minor change, but that was just the path to my JS file...mine looks like: wp_register_script( 'simplelightbox-edit', get_template_directory_uri() . '/js/simplelightbox-edit.js', [ 'jquery', 'simplelightbox' ], false, true); This is going to work, unless the author totally changes the way the plugin functions, which is unlikely. I'll still need to compare mine to their's after an update just to make sure everything matches up, but at least I'm not modifying the plugin directly :-) – Josh Rodgers Feb 12 '17 at 1:28
1

If you manually modify a plugin, the only way to keep the changes is to never update the plugin. There is a possibility of creating a wordpress hook via the functions file, but it would depend on the plugin and it may not support this.

Whenever you manually make changes to a plugin, you have two choices:

1) Never update the plugin again, or
2) Make a list of your changes (possibly in a text file you keep on your computer) so that if you want to update the plugin then you can manually go in and re-do the changes.

  • I know...unfortunately that is what I was trying to avoid. It's not a completely terrible idea, just something that I'd need to keep track of. I might do just that :-) – Josh Rodgers Feb 11 '17 at 17:14
  • Yes it is probably the only way presently. And sometimes major plugin updates may be desired, so making a list of your changes will help to replicate it later if you need to update it. – rhinos Feb 11 '17 at 20:44
0

You really want to avoid tweaking plugins, for all the reasons listed here. If you update, your changes are gone. If you don't update, you risk leaving your site open to security vulnerabilities.

The problem here is in your plugin. "Simple" means, among other things, one lightbox display per page. You need to find a plugin which will allow you to have multiple lightbox displays on a page.

  • 1
    The Simplelightbox plugin does have the capability, it's just not in the options that can be configured through the WordPress admin panel. But, I do agree with you, sometimes the easiest solution is the most obvious - find another plugin that does have that capability. I think for now, I'll keep the plugin the way it is with the minor modification I made. Not an elegant solution, but it is working. I did send the e-mail to the developer of the plugin to see if he could add an option that would allow you to define the selectors for multiple light boxes. Thanks for your reply :-) – Josh Rodgers Feb 11 '17 at 17:10
-1

I assume you mean to you want to stop the notifications?

The simplest and easiest way is to change the version of the plugin which you don't want to update. For an example if I don't want my awesome plugin to get updated, I open it's definition file, which is like:

/*
    Plugin Name: simple light
    Plugin URI: http://www.example.com/
    Version: 1.1.1

*/

Here in the Version change 1.1.1 to 9999 like:

/*
    Plugin Name: simple light
    Plugin URI: http://www.example.com/
    Version: 9999

*/
  • When a plugin is updated most of the time the plugin files change, would revert my modifications back to the default. I would like to be able to update the plugin without having my changes reverted. I was thinking there would be a function or something that I could add that would either look for that line or replace the default code with my custom code. Not bypassing the the notifications or the version, but simply finding their code and replacing it with mine. – Josh Rodgers Feb 10 '17 at 20:28
  • 1
    What a shame you already downvoted my answer. Now I don't feel inclined help any more for a question that was unclear. You question stated you were looking for how to stop a plugin from updating. Which is what I answered. it would have been better for you to clarify and let me try again rather than down voting. – rudtek Feb 10 '17 at 20:31
  • I apologize you feel that way, I feel my question was pretty clear, thank you for the contribution. – Josh Rodgers Feb 10 '17 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.