@@ -443,16 +443,17 @@ protected function enqueue_payment_form_assets() {
443
443
return ;
444
444
}
445
445
446
- $ handle = 'sv-wc-payment-gateway-payment-form ' ;
446
+ $ handle = 'sv-wc-payment-gateway-payment-form ' ;
447
+ $ versioned_handle = $ handle . '-v5_7_1 ' ;
447
448
448
449
// Frontend JS
449
- wp_enqueue_script ( " $ handle -v5_7_1 " , $ this ->get_plugin ()->get_payment_gateway_framework_assets_url () . '/js/frontend/ ' . $ handle . '.min.js ' , array ( 'jquery-payment ' ), SV_WC_Plugin::VERSION , true );
450
+ wp_enqueue_script ( $ versioned_handle , $ this ->get_plugin ()->get_payment_gateway_framework_assets_url () . '/js/frontend/ ' . $ handle . '.min.js ' , array ( 'jquery-payment ' ), SV_WC_Plugin::VERSION , true );
450
451
451
452
// Frontend CSS
452
- wp_enqueue_style ( " $ handle -v5_7_1 " , $ this ->get_plugin ()->get_payment_gateway_framework_assets_url () . '/css/frontend/ ' . $ handle . '.min.css ' , array (), SV_WC_Plugin::VERSION );
453
+ wp_enqueue_style ( $ versioned_handle , $ this ->get_plugin ()->get_payment_gateway_framework_assets_url () . '/css/frontend/ ' . $ handle . '.min.css ' , array (), SV_WC_Plugin::VERSION );
453
454
454
455
// localized JS params
455
- $ this ->localize_script ( $ handle , $ this ->get_payment_form_js_localized_script_params () );
456
+ $ this ->localize_script ( $ versioned_handle , $ this ->get_payment_form_js_localized_script_params (), ' sv_wc_payment_gateway_payment_form_params ' );
456
457
}
457
458
458
459
@@ -608,8 +609,9 @@ protected function get_gateway_js_localized_script_params() {
608
609
* @since 4.3.0
609
610
* @param string $handle script handle to localize
610
611
* @param array $params script params to localize
612
+ * @param string $object_name the localized object name. Defaults to a snake-cased version of $handle
611
613
*/
612
- protected function localize_script ( $ handle , $ params ) {
614
+ protected function localize_script ( $ handle , $ params, $ object_name = '' ) {
613
615
614
616
// If the script isn't loaded, bail
615
617
if ( ! wp_script_is ( $ handle , 'enqueued ' ) ) {
@@ -618,7 +620,10 @@ protected function localize_script( $handle, $params ) {
618
620
619
621
global $ wp_scripts ;
620
622
621
- $ object_name = str_replace ( '- ' , '_ ' , $ handle ) . '_params ' ;
623
+ // generate the object name from the handle if none is specified
624
+ if ( ! $ object_name ) {
625
+ $ object_name = str_replace ( '- ' , '_ ' , $ handle ) . '_params ' ;
626
+ }
622
627
623
628
// If the plugin's JS params already exists in the localized data, bail
624
629
if ( $ wp_scripts instanceof \WP_Scripts && strpos ( $ wp_scripts ->get_data ( $ handle , 'data ' ), $ object_name ) ) {
0 commit comments