Tuesday 26 July 2011

Breaking my website

Had a load of problems upgrading one of my sites to the latest version of wordpress. The problem wasn't with wordpress itself, but rather some modifications I'd made to the theme I was using's functions.php and also my javascript file.

One of the problems is that wordpress 3.2 requires v1.6 of jquery, but the jquery tools I was using includes jquery as part of a single file, and uses v1.4. I found the solution here: http://flowplayer.org/tools/forum/20/68683

Basically, only load jquery tools outside of the admin area, otherwise use the bundled jquery 1.6 inside the admin area.

After fixing this I was getting an error about "$ is not a function". After some googling I found that $ wasn't a global jquery variable in wordpress js and was reserved for the prototype js framework.

Now $ was only referred to in functions, and all my functions were called through
jQuery(
 function($){
  pano.init();
 }
);
So I'm not sure why it didn't work. I'm guess that it's something to do with pano being a global variable.

Anyway, to fix it I moved
jQuery(
 function($){
right up to the start of the javascript file (and left
pano.init();
 }
);
at the bottom of the file), so all the functions and variables were enclosed within the scope of the jQuery function (and no longer global).

I also had other problems with mistakes in urls etc. I made and it took me quite a bit of trying different things and googling to work out what the problems were. Anyway, fingers crossed, it seems to be working now.

No comments: