Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions woocommerce/Handlers/Script_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down
72 changes: 72 additions & 0 deletions woocommerce/Helpers/ScriptHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* WooCommerce Plugin Framework
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file license.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-3.0.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@skyverge.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the plugin to newer
* versions in the future. If you wish to customize the plugin for your
* needs please refer to http://www.skyverge.com
*
* @package SkyVerge/WooCommerce/Helpers
* @author SkyVerge
* @copyright Copyright (c) 2013-2026, SkyVerge, Inc.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*/

namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers;

class ScriptHelper
{
/**
* Adds inline JavaScript.
*
* @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 addInlineScript(string $handle, string $javaScriptString) : bool
{
if (did_action('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')) {
wp_register_script($handle, false, [], false, true);
}

if (! wp_script_is($handle, 'enqueued')) {
wp_enqueue_script($handle);
}

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.' });'
);
}
}
2 changes: 2 additions & 0 deletions woocommerce/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*** SkyVerge WooCommerce Plugin Framework Changelog ***

2025.nn.nn - version 6.0.1
* New: Introduced a new ScriptHelper class with addInlineScript() method
* Tweak: Update usage of deprecated wc_enqueue_js() in favour of wp_add_inline_script()
* Dev - Set PHP 8.1 defaults on `html_entity_decode()` usage (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401)

2025.nn.nn - version 6.0.0
Expand Down
4 changes: 3 additions & 1 deletion woocommerce/class-sv-wc-admin-notice-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1;

use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper;

defined( 'ABSPATH' ) or exit;

if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\v6_0_1\\SV_WC_Admin_Notice_Handler' ) ) :
Expand Down Expand Up @@ -304,7 +306,7 @@ function log_dismissed_notice( pluginID, messageID ) {
} ) ( jQuery );
<?php

wc_enqueue_js( ob_get_clean() );
ScriptHelper::addInlineScript($plugin_slug.'-admin-notices', ob_get_clean());
}


Expand Down
3 changes: 2 additions & 1 deletion woocommerce/class-sv-wc-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1;

use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\NumberHelper;
use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper;
use WC_Data;
use WP_Post;

Expand Down Expand Up @@ -915,7 +916,7 @@ function getEnhancedSelectFormatString() {

$javascript .= '} )();';

wc_enqueue_js( $javascript );
ScriptHelper::addInlineScript('sv-wc-select2', $javascript);

/**
* WC Select2 Ajax Rendered Action.
Expand Down
7 changes: 4 additions & 3 deletions woocommerce/payment-gateway/External_Checkout/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Blocks\Blocks_Handler;
use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Handlers\Script_Handler;
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_Payment_Gateway;
use SkyVerge\WooCommerce\PluginFramework\v6_0_1\SV_WC_Payment_Gateway_Plugin;
Expand Down Expand Up @@ -424,9 +425,9 @@ protected function should_enqueue_scripts() : bool {
* @param string $object_name JS object name
* @param string $handler_name handler class name
*/
protected function enqueue_js_handler( array $args, $object_name = '', $handler_name = '' ) {

wc_enqueue_js( $this->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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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( {
Expand All @@ -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 '<p>' . esc_html( $args['message'] ) . '</p>';
echo '<form action="' . esc_url( $args['submit_url'] ) . '" method="post">';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 6 additions & 4 deletions woocommerce/payment-gateway/class-sv-wc-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1646,6 +1647,7 @@ public function admin_options() {

parent::admin_options();

$scriptHandler = $this->get_gateway_js_handle().'-admin-inline';
?>
<style type="text/css">.nowrap { white-space: nowrap; }</style>
<?php
Expand All @@ -1668,7 +1670,7 @@ public function admin_options() {
} ).change();
<?php

wc_enqueue_js( ob_get_clean() );
ScriptHelper::addInlinejQuery($scriptHandler, ob_get_clean());

}

Expand All @@ -1692,7 +1694,7 @@ public function admin_options() {
} ).change();
<?php

wc_enqueue_js( ob_get_clean() );
ScriptHelper::addInlinejQuery($scriptHandler, ob_get_clean());
}

// if there's more than one environment include the environment settings switcher code
Expand Down Expand Up @@ -1722,7 +1724,7 @@ public function admin_options() {
} ).change();
<?php

wc_enqueue_js( ob_get_clean() );
ScriptHelper::addInlinejQuery($scriptHandler, ob_get_clean());

}

Expand All @@ -1748,7 +1750,7 @@ public function admin_options() {
} ).change();
<?php

wc_enqueue_js( ob_get_clean() );
ScriptHelper::addInlinejQuery($scriptHandler, ob_get_clean());

}

Expand Down
22 changes: 19 additions & 3 deletions woocommerce/utilities/class-sv-wp-job-batch-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace SkyVerge\WooCommerce\PluginFramework\v6_0_1;

use SkyVerge\WooCommerce\PluginFramework\v6_0_1\Helpers\ScriptHelper;

defined( 'ABSPATH' ) or exit;

if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\v6_0_1\\SV_WP_Job_Batch_Handler' ) ) :
Expand Down Expand Up @@ -87,6 +89,18 @@ protected function add_hooks() {
add_action( 'wp_ajax_' . $this->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.
Expand All @@ -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() );
}


Expand All @@ -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);
}


Expand Down
Loading