I have a conflict between two plugins that both load the same script I'm trying to resolve. I'm attempting to do so by checking if both have been loaded, and then if that's true, deregistering one of them. However, one of the scripts is always loading after the last script in wp_enqueue_scripts, no matter how high I set the priority value.
// account for conflicts between GiveWP Stripe AND WooCommerce Stripe script loading
function squarecandy_stripe_resolve() {
if ( wp_script_is('stripe') && wp_script_is('give-stripe-js') ) :
// if both scripts were loaded, remove one of them
wp_dequeue_script( 'give-stripe-js' );
else :
// this is just to test what's going wrong...
print 'stripe queued: ' . var_export(wp_script_is('stripe','to_do'),true);
print 'give-stripe-js queued: ' . var_export(wp_script_is('give-stripe-js'),true);
endif;
}
add_action( 'wp_enqueue_scripts', 'squarecandy_stripe_resolve', 999999999 );
The script give-stripe-js
is being properly identified as loaded and appears above the just-troubleshooting
line in the HTML head. But the WooCommerce Stripe script loads one line after my code and doesn't register as enqueued in my script.
Digging into the WooCommerce source I found:
class WC_Stripe_Payment_Request {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
// ...etc
What's going on here? I can't find anything in the documentation about add_action with an array passed within a class... maybe that has something to do with it? How can I do a check to see if both of these scripts have loaded after all plugins have had a chance to enqueue but before anything gets printed to the <head>
?
$this
. you can try using the 'to_do' list option (the second parameter ofwp_script_is
).print var_export(wp_script_is('stripe','to_do'),true);
This is still returning "false" in my function...wp_script_is
.