I have two plugins that work together (one is an add-on of sorts). In the “main” plugin, I have a js function in a file located like so:
wp-plugins/main-plugin-name/js/main-js.js
If my secondary plugin, I have another .js file located like so:
wp-plugins/secondary-plugin-name/js/sec-js.js
In this second plugin’s .js file, I want to use a function located in the first .js file. Basically I want the function to be globally available to both plugins.
I have already registered and enqueued the first .js script using the main plugin, but I can’t seem to get the secondary plugin to find the function from the first, and use it.
Here’s my current code:
In first plugin:
add_action( 'wp_enqueue_scripts', 'tps_enqueue_frontend_scripts');
function tps_enqueue_frontend_scripts() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_register_script( 'tps-space-rentals', $plugin_url.'/js/tps-space-rentals.js', array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-validate', 'jquery-payment', 'jquery-ui-dialog', 'jquery-ui-tooltip') );
wp_enqueue_script( 'tps-space-rentals' );
}
In my other plugin, I have this:
add_action( 'wp_enqueue_scripts', 'tps_stripe_pay_scripts_enq', 20);
function tps_stripe_pay_scripts_enq() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_register_script( 'tps-stripe-payments', $plugin_url.'js/tps-stripe-payments.js', array('jquery', 'tps-space-rentals'), '', true );
wp_enqueue_script( 'tps-stripe-payments' );
}