How to wp_dequeue_script or wp_deregister_script jquery (not effected) file from wp theme

1.1k views Asked by At

NOTE: I already use wp_dequeue_script or wp_deregister_script but not successfull

Here is the scenario, i make a image slider plugin that use jquery-cycle2 and it work successfully.

There is a user who used a wp theme and in theme there is a jquery-cycle1, now when he install my plugin the jquery-cycle1 and jquery-cycle2 conflicts, when user delete the jquery-cycle1 file all things work fine and perfectly but i don't want to delete file by user.

Now i am trying that when user install my plugin the jquery-cycle1 in theme close or deregister or stop its effect.

I get file from theme successfully

if((file_exists($theme_file_path."/jquery.cycle.all.js"))){
    echo "yes";
}

but i have no idea to close jquery-cycle1 file or stop its effect.

Last Option: I have last solution that delete the file from theme but its my last option.

Please any suggestions, help me.

2

There are 2 answers

0
Kami On

You will have to place an incompatibility notice on your theme.

It is not possible to attempt to detect the existence of script from server side. You are able to detect queued scripts via the word press methods, however, this assumes that the user has not simply linked the file with a <script></script> tag. The file_exists method assume the file is stored on the server itself - it could be linked from a CDN or another server.

Also, whatever methods you use to detect and remove jQuery-Cycle; You are going to break any feature on the site that uses the existing plugin.

Thus, any solution you able to devise would either be extremely complicated, or would not be generalised enough to account for all these possibilities.

You may be able to use the following to prevent loading your script

if (jQuery().cycle) {
   // Script already loaded
   console.log("Error: Another version of jQuery-Cycle is already loaded!");
} else {
   // Load your script
}

but this cannot unload what is already loaded.

0
tinker On

There is a simple hack you can do on you end. In the Cycle2 source replace all $.fn.cycle with $.fn.cycle2 and ).cycle( to ).cycle2(. I am using the source from here http://malsup.github.io/jquery.cycle2.js

After that You can access it like

$("#id").cycle2({option})

Here is a demo http://jsfiddle.net/33g6z79h/

Here i assume that you are not using cycle events http://jquery.malsup.com/cycle2/api/#events and cycle extra transitions. If you are using it you can make a fiddle for your cycle2 implementation and i would be glad to help :)