-
Notifications
You must be signed in to change notification settings - Fork 216
Update script handles to WooCommerce standards #2966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,18 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function get_wc_handler( $handler ): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // map legacy handlers to new ones | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $handlers = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'jquery-blockui' => 'jquery-blockui', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'jquery-tiptip' => 'jquery-tiptip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( version_compare( WC()->version, '10.3.0', '>=' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 'wc-' . $handlers[ $handler ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $handlers[ $handler ] ?? $handler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Fix undefined array key access and refactor handler mapping. The current implementation has a critical bug when an unknown handler is passed with WooCommerce >= 10.3.0. On line 39, Additionally, the mapping array is redundant since keys and values are identical—it's not actually "mapping" anything, just whitelisting known handlers. Apply this refactored implementation: public static function get_wc_handler( $handler ): string {
- // map legacy handlers to new ones
- $handlers = [
+ // Whitelist of WC handlers that require version-specific prefixing
+ $supported_handlers = [
'jquery-blockui' => 'jquery-blockui',
'jquery-tiptip' => 'jquery-tiptip',
];
+
+ // Return original handler if not in our supported list
+ if ( ! isset( $supported_handlers[ $handler ] ) ) {
+ return $handler;
+ }
+
+ // For WC 10.3.0+, use 'wc-' prefix
if ( version_compare( WC()->version, '10.3.0', '>=' ) ) {
- return 'wc-' . $handlers[ $handler ];
+ return 'wc-' . $supported_handlers[ $handler ];
}
- return $handlers[ $handler ] ?? $handler;
+
+ return $supported_handlers[ $handler ];
}Alternatively, simplify further by using an array of strings: public static function get_wc_handler( $handler ): string {
- // map legacy handlers to new ones
- $handlers = [
- 'jquery-blockui' => 'jquery-blockui',
- 'jquery-tiptip' => 'jquery-tiptip',
- ];
+ // Whitelist of WC handlers that require version-specific prefixing
+ $supported_handlers = [ 'jquery-blockui', 'jquery-tiptip' ];
+
+ // Return original handler if not in our supported list
+ if ( ! in_array( $handler, $supported_handlers, true ) ) {
+ return $handler;
+ }
+
+ // For WC 10.3.0+, use 'wc-' prefix
if ( version_compare( WC()->version, '10.3.0', '>=' ) ) {
- return 'wc-' . $handlers[ $handler ];
+ return 'wc-' . $handler;
}
- return $handlers[ $handler ] ?? $handler;
+
+ return $handler;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Load global admin and promo notices scripts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -163,7 +175,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function get_localized_price() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'precision' => wc_get_price_decimals(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'symbol' => html_entity_decode( get_woocommerce_currency_symbol() ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 178 in includes/Assets.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'decimal' => esc_attr( wc_get_price_decimal_separator() ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'thousand' => esc_attr( wc_get_price_thousand_separator() ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'position' => esc_attr( get_option( 'woocommerce_currency_pos' ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -376,6 +388,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function get_scripts() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global $wp_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $jquery_tiptip = self::get_wc_handler( 'jquery-tiptip' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $frontend_shipping_asset = require DOKAN_DIR . '/assets/js/frontend.asset.php'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -493,7 +506,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'dokan-script' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'src' => $asset_url . '/js/dokan.js', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'deps' => [ 'imgareaselect', 'customize-base', 'customize-model', 'wp-i18n', 'jquery-tiptip', 'moment', 'dokan-date-range-picker', 'dokan-accounting' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'deps' => [ 'imgareaselect', 'customize-base', 'customize-model', 'wp-i18n', $jquery_tiptip, 'moment', 'dokan-date-range-picker', 'dokan-accounting' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'version' => filemtime( $asset_path . 'js/dokan.js' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'dokan-vue-vendor' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -584,8 +597,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! wp_script_is( 'jquery-tiptip', 'registered' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $scripts['jquery-tiptip'] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( ! wp_script_is( $jquery_tiptip, 'registered' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $scripts[ $jquery_tiptip ] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'src' => WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'deps' => $require_dompurify ? [ 'jquery', 'dompurify' ] : [ 'jquery' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did not check the
$handlers[ $handler ];isset or not.Pls check the coderabbit suggestion.