I'm developing a plugin that use a Google Maps API. The plugin enqueuing script in this way:
wp_enqueue_script('google-maps', 'http://maps.google.com/maps/api/js?sensor=false&callback=initialize&language=en-us', array('jquery'), false, true);
Considering the fact that other plugins/themes may use same maps library, while $handle
could be different, the validation wp_script_is($handle,'registered')
does not makes sence. Duplicating of enqueued script leads to JS error:
You have included the Google Maps API multiple times on this page. This may cause unexpected errors.
Regarding things described I've build a code that search thought $wp_scripts
for Google Maps scripts and unset it, in case if found:
global $wp_scripts;
foreach ($wp_scripts->registered as $key => $script) {
if (preg_match('#maps\.google(?:\w+)?\.com/maps/api/js#', $script->src)) {
unset($wp_scripts->registered[$key]);
}
}
The question is: how can I check and reassign dependencies of the removed scripts (in case if they're set by other plugins/themes). What will happens and how to deal with the fact that multiple plugins may use the same &callback=initialize
parameter of Google Maps API script.