[wp-hackers] Note for plugin development using js in admin

Owen Winkler ringmaster at midnightcircus.com
Sun Jan 15 01:46:01 GMT 2006


The 2.0.1 release seems to be moving all of the core javascript into its 
own files and making the script includes conditional based on what the 
page needs.

That's all fine except it might not be clear where to tell WordPress to 
use the javascript.

Apparently, the hook to use is admin_menu.  Set one of the following 
variables:

add_action('admin_menu', 'admin_menu');
function admin_menu() {
	global $xfn_js, $sack_js, $list_js, $dbx_js;

	$xfn_js = true; // Include the XFN script
	$sack_js = true; // Incluce the tw-sack script
	$list_js = true; // Include the list manipulation script
	$dbx_js = true; // Include the DBX script
}

Note that inserting these script via the admin_header hook seems like a 
bad idea, since two plugins doing this could cause some "interesting" 
collisions.

You might also like to check to see if it's your page that's actually 
loading, so that you're not loading the scripts unnecessarily.  I tried 
this method, and it worked for me:

if(isset($_GET['page']) && ($_GET['page'] == plugin_basename(__FILE__)))
...

Just a note to all plugin devs for 2.0.1, which will likely break your 
existing plugins if you're using the built-in tw-sack for Ajax, since 
it's not included in the admin head by default any more.

Owen




More information about the wp-hackers mailing list