2014-05-03, 02:43 PM
I'm working to update my SimpleLikes plugin and am running across a bizarre issue with the find_replace_templatesets function. This is my code:
The issue is that every time I run the activate function, my JavaScript gets inserted twice. I need to replace it at the end of the template so that my custom JS has access to some of the earlier defined variables (such as my_post_key).
I can't quite work out what's causing this at all... Any ideas would be appreciated.
$simpleLikesJavascript = <<<HTML
$1
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script type="text/javascript" src="{\$mybb->settings['bburl']}/jscripts/like_system.js"></script>
HTML;
find_replace_templatesets(
'headerinclude',
'/(.*)$/',
$simpleLikesJavascript
);
The issue is that every time I run the activate function, my JavaScript gets inserted twice. I need to replace it at the end of the template so that my custom JS has access to some of the earlier defined variables (such as my_post_key).
I can't quite work out what's causing this at all... Any ideas would be appreciated.