Plugin Author
Arnan
(@adegans)
Sounds like a Autoptimize issue. They alter the code causing that error 😉
Or is the error also visible without Autoptimize?
And what is the error?
So it seems the problem is that you don’t specify jquery as a dependency when you enqueue the script, and in this case your script is getting enqueued before jquery, so it doesn’t work.
In version 3.11.7 of AdRotate, in file adrotate-output.php, line 472 is :
wp_enqueue_script(‘clicktrack-adrotate’, plugins_url(‘/library/jquery.adrotate.clicktracker.js’, __FILE__), false, null, $in_footer);
and it should be :
wp_enqueue_script(‘clicktrack-adrotate’, plugins_url(‘/library/jquery.adrotate.clicktracker.js’, __FILE__), array(‘jquery’), null, $in_footer);
Plugin Author
Arnan
(@adegans)
That only works if the theme doesn’t hardcode some 3rd party jQuery thing.
Which happens all too often.
Tick the “load javascript in footer” checkbox in AdRotate settings to sort out the loading order.
Sorry, i should have mentioned that i had already checked “load javascript in footer”. But jquery.adrotate.clicktracker.js still loads before jQuery.
It seems also that it is being loaded even when there are no active ads.
Plugin Author
Arnan
(@adegans)
If jQuery gets loaded behind the other scripts then that’s the real problem 😉
If you’re using the version shipped with WordPress it’s loaded in the right order.
Depending on how you include a 3rd party version the order may differ.
Maybe that’s how it *should* be, but the code actually generated by your plugin shows it’s not the case. Here is what we are getting :
<script type=’text/javascript’>
/* <![CDATA[ */
var click_object = {“ajax_url”:”http:\/\/ancronmedical.com\/wp-admin\/admin-ajax.php”};
/* ]]> */
</script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-content/plugins/adrotate/library/jquery.adrotate.clicktracker.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-includes/js/jquery/jquery.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-includes/js/jquery/jquery-migrate.min.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-content/plugins/google-maps-widget/js/jquery.colorbox.min.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-content/plugins/google-maps-widget/js/gmw.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-content/themes/nelson-base/js/wildmice.min.js’></script>
<script type=’text/javascript’ src=’http://ancronmedical.com/wp-content/themes/nelson-base/js/picturefill.min.js’></script>
This is with scripts being loaded at the end of the page. As you can see, your script gets loaded before jquery because its dependency on jquery is not declared in the enqueue. The code snippet i posted earlier resolves this problem for us.
The AdRotate script only works because jquery happens to get loaded before your script executes. The reason why it matters is because this interferes with a plugin (Autoptimize) that uses the enqueued order.
Note that this is the regular WordPress version of jQuery, loaded at the end, and jQuery does indeed get loaded *after* your script.
Plugin Author
Arnan
(@adegans)
Then add the dependency if that fixes the order for you.
None of the themes/minifying plugins I’ve tested and seen exhibit this issue.
I can’t fix the loading order if your plugin overrules it and adding the dependency creates a bunch of other problems for people using crap themes.
I’ll review the dependency thing for a near future version and see if it’s still ‘required’ to omit it but for now there is not much I can do about it
Hi Arnan,
I’m thinking maybe you missed the point here. The Autoptimize plugin gets the order of scripts from WordPress. Whatever order they are queued in (explicitly or by default) is what the plugin will use.
So in the case of AdRotate, they are not being queued in the right order. Your plugin only works by accident/good luck because fortunately your script does not execute before jQuery is loaded, even though jQuery is loaded *after* yours.
I did of course add the dependency and it solved the problem for me because then Autoptimize got the correct order from core. But i cannot use a modified version of your plugin because then i’d be excluded from future updates or updates would erase my mod. So i have little choice but to either hope you resolve this, or else i’ll just not be able to use AdRotate.
I’d like to re-iterate that Autoptimize does not overrule your loading order. It is using it. That’s the problem. As soon as you put all scripts into one file, in the order that WordPress queues them, the order becomes critical and it will no longer work by coincidence as it does now with separate files.