From 07d507081c5d09f87ae3e38976293bea8719ed93 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 17 Feb 2026 12:43:47 +0000 Subject: [PATCH 1/5] Replace usage of deprecated wc_enqueue_js --- woocommerce/Handlers/Script_Handler.php | 15 ++++++ woocommerce/Helpers/ScriptHelper.php | 48 +++++++++++++++++++ woocommerce/changelog.txt | 2 + .../class-sv-wc-admin-notice-handler.php | 4 +- woocommerce/class-sv-wc-helper.php | 3 +- .../External_Checkout/Frontend.php | 7 +-- .../class-sv-wc-payment-gateway-hosted.php | 7 ++- ...-wc-payment-gateway-my-payment-methods.php | 6 +-- ...ass-sv-wc-payment-gateway-payment-form.php | 2 +- .../class-sv-wc-payment-gateway.php | 10 ++-- .../class-sv-wp-job-batch-handler.php | 22 +++++++-- 11 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 woocommerce/Helpers/ScriptHelper.php diff --git a/woocommerce/Handlers/Script_Handler.php b/woocommerce/Handlers/Script_Handler.php index 1dc1862ba..70ee64ac0 100644 --- a/woocommerce/Handlers/Script_Handler.php +++ b/woocommerce/Handlers/Script_Handler.php @@ -24,6 +24,7 @@ namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1\Handlers; +use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\SV_WC_Helper; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\SV_WC_Plugin_Exception; @@ -287,6 +288,20 @@ public function ajax_log_event() { } + /** + * Adds inline JavaScript to the page. + * + * @since 6.0.1 + * + * @param string $data The JavaScript code to add inline + * @return bool True if successfully added + */ + protected function addInlineScript(string $data): bool + { + return ScriptHelper::addInlineScript($this->get_id().'-inline-scripts', $data); + } + + /** * Adds a log entry. * diff --git a/woocommerce/Helpers/ScriptHelper.php b/woocommerce/Helpers/ScriptHelper.php new file mode 100644 index 000000000..b86edc02a --- /dev/null +++ b/woocommerce/Helpers/ScriptHelper.php @@ -0,0 +1,48 @@ +get_safe_handler_js( $args, $handler_name, $object_name ) ); + protected function enqueue_js_handler(array $args, $object_name = '', $handler_name = '') + { + $this->addInlineScript($this->get_safe_handler_js($args, $handler_name, $object_name)); } diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-hosted.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-hosted.php index ea73bf5f2..c5b99eac2 100644 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-hosted.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-hosted.php @@ -25,6 +25,7 @@ namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\OrderHelper; +use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper; defined( 'ABSPATH' ) or exit; @@ -250,7 +251,7 @@ public function render_auto_post_form( \WC_Order $order, $request_params ) { $args = $this->get_auto_post_form_args( $order ); // attempt to automatically submit the form and redirect - wc_enqueue_js(' + $script = ' ( function( $ ) { $( "body" ).block( { @@ -273,7 +274,9 @@ public function render_auto_post_form( \WC_Order $order, $request_params ) { $( "#submit_' . $this->get_id() . '_payment_form" ).click(); } ) ( jQuery ); - '); + '; + + ScriptHelper::addInlineScript($this->get_gateway_js_handle().'-inline', $script); echo '

' . esc_html( $args['message'] ) . '

'; echo '
'; diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-my-payment-methods.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-my-payment-methods.php index 8f0cff402..8910193a6 100644 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-my-payment-methods.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-my-payment-methods.php @@ -1156,9 +1156,9 @@ public function handle_payment_method_actions() { * * @since 5.1.0 */ - public function render_js() { - - wc_enqueue_js( $this->get_safe_handler_js() ); + public function render_js() + { + $this->addInlineScript($this->get_safe_handler_js()); } diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-payment-form.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-payment-form.php index 44e85c287..a44cc39d0 100644 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway-payment-form.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway-payment-form.php @@ -1098,7 +1098,7 @@ public function render_js() { break; case "wc_{$gateway_id}_payment_form_end" : $this->payment_form_js_rendered[] = $gateway_id; - wc_enqueue_js( $this->get_safe_handler_js() ); + $this->addInlineScript($this->get_safe_handler_js()); break; endswitch; } diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php index 1c3287571..f3a878306 100755 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php @@ -27,6 +27,7 @@ use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Blocks\Blocks_Handler; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\OrderHelper; +use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Payment_Gateway\Blocks\Gateway_Checkout_Block_Integration; use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Payment_Gateway\Dynamic_Props; use stdClass; @@ -1646,6 +1647,7 @@ public function admin_options() { parent::admin_options(); + $scriptHandler = $this->get_gateway_js_handle().'-admin-inline'; ?> get_job_handler()->get_identifier() . '_cancel_job', array( $this, 'ajax_cancel_job' ) ); } + /** + * Gets the name of the script handle. + * + * @since 6.0.1 + * + * @return string + */ + protected function getScriptHandle() : string + { + return $this->get_job_handler()->get_identifier() . '_batch_handler'; + } + /** * Enqueues the scripts. @@ -95,7 +109,7 @@ protected function add_hooks() { */ public function enqueue_scripts() { - wp_enqueue_script( $this->get_job_handler()->get_identifier() . '_batch_handler', $this->get_plugin()->get_framework_assets_url() . '/js/admin/sv-wp-admin-job-batch-handler.min.js', [ 'jquery' ], $this->get_plugin()->get_assets_version() ); + wp_enqueue_script( $this->getScriptHandle(), $this->get_plugin()->get_framework_assets_url() . '/js/admin/sv-wp-admin-job-batch-handler.min.js', [ 'jquery' ], $this->get_plugin()->get_assets_version() ); } @@ -116,11 +130,13 @@ protected function render_js() { */ $args = apply_filters( $this->get_job_handler()->get_identifier() . '_batch_handler_js_args', $this->get_js_args(), $this ); - wc_enqueue_js( sprintf( 'window.%1$s_batch_handler = new %2$s( %3$s );', + $script = sprintf( 'window.%1$s_batch_handler = new %2$s( %3$s );', esc_js( $this->get_job_handler()->get_identifier() ), esc_js( $this->get_js_class() ), json_encode( $args ) - ) ); + ); + + ScriptHelper::addInlineScript($this->getScriptHandle(), $script); } From 9c6fe96d79db4c3acd292acdc8a96c23701267cd Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 17 Feb 2026 12:45:31 +0000 Subject: [PATCH 2/5] Separate out registration --- woocommerce/Helpers/ScriptHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/woocommerce/Helpers/ScriptHelper.php b/woocommerce/Helpers/ScriptHelper.php index b86edc02a..562e787e1 100644 --- a/woocommerce/Helpers/ScriptHelper.php +++ b/woocommerce/Helpers/ScriptHelper.php @@ -38,8 +38,11 @@ class ScriptHelper */ public static function addInlineScript(string $handle, string $javaScriptString, array $dependencies = []) : bool { - if (! wp_script_is($handle, 'enqueued')) { + if (! wp_script_is($handle, 'registered')) { wp_register_script($handle, '', $dependencies, false, true); + } + + if (! wp_script_is($handle, 'enqueued')) { wp_enqueue_script($handle); } From 090e21f1438f8ed9a0d063e60b8be9df5ce474c0 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 17 Feb 2026 13:35:57 +0000 Subject: [PATCH 3/5] Remove dependencies & add doing it wrong check --- woocommerce/Helpers/ScriptHelper.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/woocommerce/Helpers/ScriptHelper.php b/woocommerce/Helpers/ScriptHelper.php index 562e787e1..208586eb4 100644 --- a/woocommerce/Helpers/ScriptHelper.php +++ b/woocommerce/Helpers/ScriptHelper.php @@ -33,13 +33,16 @@ class ScriptHelper * * @param string $handle Handle name * @param string $javaScriptString The JavaScript code to add inline - * @param array $dependencies Optional dependencies * @return bool True if successfully added */ - public static function addInlineScript(string $handle, string $javaScriptString, array $dependencies = []) : bool + public static function addInlineScript(string $handle, string $javaScriptString) : bool { + if (did_action('wp_print_footer_scripts')) { + _doing_it_wrong(__METHOD__, 'This should be called before wp_print_footer_scripts'); + } + if (! wp_script_is($handle, 'registered')) { - wp_register_script($handle, '', $dependencies, false, true); + wp_register_script($handle, false, [], false, true); } if (! wp_script_is($handle, 'enqueued')) { From 34b009f0b174d1128a71327ce76bd7fadc63a5c5 Mon Sep 17 00:00:00 2001 From: Ashley Gibson <99189195+agibson-godaddy@users.noreply.github.com> Date: Tue, 17 Feb 2026 13:50:50 +0000 Subject: [PATCH 4/5] Update doing it wrong wording Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- woocommerce/Helpers/ScriptHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce/Helpers/ScriptHelper.php b/woocommerce/Helpers/ScriptHelper.php index 208586eb4..808428949 100644 --- a/woocommerce/Helpers/ScriptHelper.php +++ b/woocommerce/Helpers/ScriptHelper.php @@ -38,7 +38,7 @@ class ScriptHelper public static function addInlineScript(string $handle, string $javaScriptString) : bool { if (did_action('wp_print_footer_scripts')) { - _doing_it_wrong(__METHOD__, 'This should be called before wp_print_footer_scripts'); + _doing_it_wrong(__METHOD__, 'Inline scripts should be added before the wp_print_footer_scripts action.', '6.0.1'); } if (! wp_script_is($handle, 'registered')) { From 7fd562e168bfa2501c13d4cf1b800471b8a0d986 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Tue, 17 Feb 2026 14:05:11 +0000 Subject: [PATCH 5/5] Add jQuery helper --- woocommerce/Helpers/ScriptHelper.php | 18 ++++++++++++++++++ .../class-sv-wc-payment-gateway.php | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/woocommerce/Helpers/ScriptHelper.php b/woocommerce/Helpers/ScriptHelper.php index 208586eb4..c5f196564 100644 --- a/woocommerce/Helpers/ScriptHelper.php +++ b/woocommerce/Helpers/ScriptHelper.php @@ -51,4 +51,22 @@ public static function addInlineScript(string $handle, string $javaScriptString) return wp_add_inline_script($handle, $javaScriptString); } + + /** + * Adds inline jQuery. + * This calls {@see static::addInlineScript()} but with automatic jQuery wrapping. + * + * @since 6.0.1 + * + * @param string $handle Handle name + * @param string $javaScriptString The JavaScript code to add inline + * @return bool True if successfully added + */ + public static function addInlinejQuery(string $handle, string $javaScriptString) : bool + { + return static::addInlineScript( + $handle, + 'jQuery(function($) { '.$javaScriptString.' });' + ); + } } diff --git a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php index f3a878306..5e5af2547 100755 --- a/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php +++ b/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php @@ -1670,7 +1670,7 @@ public function admin_options() { } ).change();