Skip to content

Conversation

@kzamanbd
Copy link
Contributor

@kzamanbd kzamanbd commented Nov 6, 2025

Refactored script registration and enqueuing to use dynamic handler names for 'jquery-blockui' and 'jquery-tiptip' based on WooCommerce version. Introduced Assets::get_wc_handler() to map legacy handlers to new ones, ensuring compatibility with WooCommerce 10.3.0 and above.

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Refactor
    • Streamlined script asset handling to improve compatibility across WooCommerce versions, ensuring robust dependency management for setup wizard functionality.

Refactored script registration and enqueuing to use dynamic handler names for 'jquery-blockui' and 'jquery-tiptip' based on WooCommerce version. Introduced Assets::get_wc_handler() to map legacy handlers to new ones, ensuring compatibility with WooCommerce 10.3.0 and above.
@kzamanbd kzamanbd requested a review from mrabbani November 6, 2025 04:53
@kzamanbd kzamanbd self-assigned this Nov 6, 2025
@kzamanbd kzamanbd added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Nov 6, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

This PR refactors legacy WC script handle usage by introducing a new get_wc_handler() method in the Assets class that dynamically maps deprecated script handles (jquery-blockui, jquery-tiptip) to current WC versions. The method is then applied across SetupWizard implementations to replace hardcoded handle references with dynamic ones.

Changes

Cohort / File(s) Summary
Core handler mapping
includes/Assets.php
Adds public static method get_wc_handler($handler) that returns version-conditional script handles (prefixed with wc- for WC ≥ 10.3.0); refactors script dependencies to use dynamic handles instead of hardcoded jquery-tiptip strings.
SetupWizard implementations
includes/Admin/SetupWizard.php,
includes/Admin/SetupWizardNoWC.php,
includes/Vendor/SetupWizard.php
Imports Assets class; replaces hardcoded script handle references (jquery-blockui, jquery-tiptip) with dynamic calls to Assets::get_wc_handler() in script registration and dependency arrays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • The new method in Assets.php contains straightforward version-conditional logic with clear intent
  • Changes across SetupWizard files follow a consistent, repetitive refactoring pattern (same replacements applied multiple times)
  • No complex logic changes or structural modifications; primarily utility method creation and reference updates

Possibly related PRs

Suggested reviewers

  • mrabbani
  • shohag121

Poem

🐰 Hops with glee!

Old handles fade to history,
Dynamic paths now set them free,
No warnings cry from jQuery's tree,
A cleaner setup, clear as can be! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive PR description provides a summary but lacks crucial details required by the template, including incomplete testing instructions, missing changelog entry, and no before/after descriptions. Complete the following sections: provide specific testing steps or link the issue, add a changelog title and detailed description of behavioral changes, include before/after descriptions with screenshots if applicable, and confirm all checklist items have been properly addressed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: refactoring script handles to use WooCommerce standards instead of hard-coded legacy handles.
Linked Issues check ✅ Passed The PR successfully addresses the core requirement of issue #5079: refactoring 'jquery-blockui' and 'jquery-tiptip' handles to resolve deprecation warnings by implementing dynamic handler resolution.
Out of Scope Changes check ✅ Passed All changes are directly scoped to refactoring script handle usage for WooCommerce compatibility; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/wc-deps-handle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be5afb8 and e6a9d9c.

📒 Files selected for processing (4)
  • includes/Admin/SetupWizard.php (2 hunks)
  • includes/Admin/SetupWizardNoWC.php (2 hunks)
  • includes/Assets.php (4 hunks)
  • includes/Vendor/SetupWizard.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
includes/Vendor/SetupWizard.php (1)
includes/Assets.php (2)
  • Assets (12-1406)
  • get_wc_handler (32-42)
includes/Admin/SetupWizard.php (1)
includes/Assets.php (2)
  • Assets (12-1406)
  • get_wc_handler (32-42)
includes/Admin/SetupWizardNoWC.php (1)
includes/Assets.php (2)
  • Assets (12-1406)
  • get_wc_handler (32-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: e2e tests (3, 3)
🔇 Additional comments (4)
includes/Assets.php (1)

391-391: LGTM with dependency on get_wc_handler fix.

The usage of the new get_wc_handler() method is implemented correctly:

  • Handler is computed once and stored in a variable (line 391)
  • Consistently used in dependency arrays (line 509)
  • Properly used in conditional registration logic (lines 600-605)

Once the critical bug in get_wc_handler() is fixed, this implementation will work correctly for all WooCommerce versions.

Also applies to: 509-509, 600-605

includes/Vendor/SetupWizard.php (1)

7-7: LGTM! Clean implementation of dynamic WC asset handling.

The vendor setup wizard correctly:

  • Imports the Assets class (line 7)
  • Retrieves dynamic handles for both WooCommerce scripts (lines 104-105)
  • Enqueues scripts using the dynamic handles (lines 109-110)

This ensures compatibility with both legacy and modern WooCommerce versions.

Also applies to: 104-110

includes/Admin/SetupWizardNoWC.php (1)

6-6: LGTM! Consistent dynamic asset handling.

The no-WC setup wizard properly:

  • Imports the Assets class (line 6)
  • Retrieves the dynamic jquery-blockui handle (line 46)
  • Registers the script using the dynamic handle (line 47)
  • Uses it in the wc-setup script dependencies (line 51)

The implementation is clean and follows the same pattern as other setup wizards.

Also applies to: 46-47, 51-51

includes/Admin/SetupWizard.php (1)

6-6: LGTM! Thorough implementation with proper conditional checks.

The admin setup wizard correctly:

  • Imports the Assets class (line 6)
  • Retrieves dynamic handles for both WooCommerce scripts (lines 155-156)
  • Conditionally registers jquery-tiptip only if not already registered (lines 158-160)
  • Uses both dynamic handles in the wc-setup script dependencies (line 162)

The conditional registration check is a nice defensive pattern that prevents duplicate registrations.

Also applies to: 155-162

Comment on lines +32 to +42
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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, $handlers[$handler] will trigger an undefined array key warning if the handler isn't in the mapping, and concatenating with 'wc-' will produce an invalid handle like 'wc-' (empty suffix).

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
}
public static function get_wc_handler( $handler ): string {
// 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-' . $supported_handlers[ $handler ];
}
return $supported_handlers[ $handler ];
}
🤖 Prompt for AI Agents
In includes/Assets.php around lines 32-42, replace the current associative
$handlers usage that accesses $handlers[$handler] (causing undefined key
warnings) with a whitelist array of handler names (simple strings) and guard the
WC version branch with an existence check; specifically, create an array like
$allowed = ['jquery-blockui','jquery-tiptip']; then if
version_compare(WC()->version,'10.3.0','>=' ) return 'wc-'.$handler only when
in_array($handler,$allowed,true) else return $handler; for older versions just
return $handler (or return $handler when not in the whitelist) so no undefined
array key access occurs and the mapping is simplified.

@kzamanbd kzamanbd added the DO NOT MERGE Don't merge this PR label Nov 6, 2025
Comment on lines +38 to +40
if ( version_compare( WC()->version, '10.3.0', '>=' ) ) {
return 'wc-' . $handlers[ $handler ];
}
Copy link
Member

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.

@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DO NOT MERGE Don't merge this PR Needs: Author Reply Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants