Can wp_script_is
used in pluginA
check if a script is being enqueued/registered from pluginB
?
I have two plugins both of which use Angular. One plugin (pluginA) has angular.min.js
being loaded across all pages. The other (pluginB) has angular.min.js
being loaded on only one. I would like to check if pluginA
has already enqueued Angular but I want to do it from pluginB
.
For instance, I tried
$handle = 'myAppScript.min.js' // this is a concatenated/minified version of the entire pluginA angular app.
$list = 'enqueued' // I also tried all the other $list options.
// if 'myAppScript.min.js' is present, don't register Angular again, otherwise register it.
if (wp_script_is($handle, $list)) {
return;
} else {
wp_register_script( $this->plugin_name . '-ajs', plugin_dir_url(__FILE__) . 'js/angular/angular.min.js', array(), $this->version, false );
}
However wp_script_is
returns false no matter what I try (I double checked with a var_dump
) and therefore adds Angular again.
Thanks for any help you can give!
Update - I have a working solution to my particular problem using is_plugin_active
, but I'm still curious if there's an answer to the question. Thanks!
$plugin = 'pluginA/pluginA.php';
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (!is_plugin_active($plugin)) {
wp_register_script( $this->plugin_name . '-ajs', plugin_dir_url(__FILE__) . 'js/angular/angular.min.js', array(), $this->version, false );
}
wp_script_is
? If it is called before thewp_enqueue_scripts
action is fired, then it should return 0. codex.wordpress.org/Plugin_API/…is_plugin_active
.