[wp-hackers] strange problem including external JS file in WP admin

Steve Taylor steve at sltaylor.co.uk
Mon Oct 25 11:45:06 UTC 2010


Hi there,

I've just been addressing an issue on a client site, they were having
strange problems with media uploading. I didn't do extensive browser
testing, but the symptoms always appeared in Firefox, and never (for
me) in Chrome (although my client said they occasionally got the
problems in Chrome, too).

The main symptom is that when you click to "Set featured image" while
editing a post, the media pop-up lacked the tabs at the top. You could
upload an image, but when you click "Use as featured image", it
changed to "Saving..." and stuck there - it never saved.

I've also noticed things such as, the left nav in admin not
remembering its state (folded out or in), and the "Publish" controls
on the post edit screen always being open (i.e. as if you've clicked
"Edit" next to Status, Visibility, etc.)

I've spent a while debugging, and tracked it down to some code in my
custom theme that includes JS in the admin header.

Now obviously I assumed it was something to do with my jQuery in the
JS file being included. But it seems to be purely the fact of included
an external JS file. I've narrowed it down quite specifically by
installing a fresh 3.0.1, and adding the following code to the top of
the default theme's functions.php:

function customAdmin() { ?>
	<script type="text/javascript" src="<?php bloginfo(
'template_directory' ); ?>/js-wp.js" />
<?php }
add_action( 'admin_head', 'customAdmin' );

It doesn't appear to matter whether js-wp.js exists, or what is in it
if it does. And, according to my testing, whatever JS you want to
include will work fine (with none of the above side-effects) if you
just include it inline in the header code. It seems that all the above
problems are triggered by the mere inclusion by a theme of a script
tag with the src attribute in the admin header.

Can anyone else confirm this? Any ideas about why it's happening?

cheers,

Steve Taylor


More information about the wp-hackers mailing list