[wp-hackers] Pattern for script and option sharing between plugins?
dylan.k.kuhn at gmail.com
Thu Apr 9 21:04:48 GMT 2009
My plugin uses the Google Maps API, and has until now stored the API key in
its own options. As I work on using the Google AJAX APIs  to load
Google's scripts, I'm wondering if I should make the jsapi loader script
sharable between plugins? I know it will become more common for a site to
have multiple plugins using proprietary Google APIs, and I can see those
scripts getting loaded multiple times with different API keys by different
Here's what I was thinking of doing:
$google_api_key = get_option( 'google_api_key');
If that exists I'll use it, otherwise I'll store my previously private key
there. I'll also register a script using it:
wp_register_script( 'google-jsapi', 'http://www.google.com/jsapi?key=' .
If I understand correctly, it shouldn't matter if another plugin does this
also, the first one wins, then everyone should be able to enqueue the
script. Is this a good idea, or just hopeless namespace clutter?
I also read the thread considering using the Google AJAX API in the core. It
seems to me that for now, at least, it would be important _not_ to use it to
load jQuery or other scripts that WP already manages.
More information about the wp-hackers