fix: guard wubox clicks before scripts load#1596
Conversation
📝 WalkthroughWalkthroughIntroduces an early wubox click guard script in the Scripts class, centralizing its JavaScript generation into a helper method and printing it via an admin_head hook on WP Ultimo pages. Adds corresponding unit tests validating the generated script content and its attachment to the registered wubox script. ChangesWubox Early Click Guard
Sequence Diagram(s)sequenceDiagram
participant WordPress
participant Scripts
participant DocumentHead
WordPress->>Scripts: init()
Scripts->>Scripts: register_default_scripts()
Scripts->>Scripts: get_wubox_early_click_guard_script()
Scripts->>Scripts: wp_add_inline_script(wubox, guard script)
WordPress->>Scripts: admin_head action (priority 1)
Scripts->>Scripts: print_wubox_early_click_guard()
Scripts->>DocumentHead: output <script> tag with guard JS
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/WP_Ultimo/Scripts_Test.php (1)
279-291: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the actual head output path.
This checks the footer
beforepayload, but notprint_wubox_early_click_guard()’s page/enqueue gate or emitted<script id="wu-wubox-early-click-guard">.Suggested test coverage
+ public function test_print_wubox_early_click_guard_outputs_script_when_wubox_enqueued(): void { + + $force_wu_page = static fn() => true; + add_filter('wu_is_wu_page', $force_wu_page); + + $this->scripts->register_default_scripts(); + wp_enqueue_script('wubox'); + + ob_start(); + $this->scripts->print_wubox_early_click_guard(); + $output = ob_get_clean(); + + remove_filter('wu_is_wu_page', $force_wu_page); + wp_dequeue_script('wubox'); + + $this->assertStringContainsString('id="wu-wubox-early-click-guard"', $output); + $this->assertStringContainsString('window.__wuboxEarlyClicks=window.__wuboxEarlyClicks||[];', $output); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/WP_Ultimo/Scripts_Test.php` around lines 279 - 291, The current test only inspects the stored wp_scripts data for wubox and misses the real head output path from print_wubox_early_click_guard(). Add coverage that exercises the page/enqueue gate in Scripts_Test by triggering the conditions that cause the guard to render, then assert the emitted <script id="wu-wubox-early-click-guard"> appears in the actual output. Keep the existing register_default_scripts check for the footer payload, but add a separate test that verifies the early click guard is printed through print_wubox_early_click_guard() rather than only reading wp_scripts()->get_data().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/WP_Ultimo/Scripts_Test.php`:
- Around line 279-291: The current test only inspects the stored wp_scripts data
for wubox and misses the real head output path from
print_wubox_early_click_guard(). Add coverage that exercises the page/enqueue
gate in Scripts_Test by triggering the conditions that cause the guard to
render, then assert the emitted <script id="wu-wubox-early-click-guard"> appears
in the actual output. Keep the existing register_default_scripts check for the
footer payload, but add a separate test that verifies the early click guard is
printed through print_wubox_early_click_guard() rather than only reading
wp_scripts()->get_data().
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e68f6652-57f5-4275-89ca-556177bf62b8
📒 Files selected for processing (2)
inc/class-scripts.phptests/WP_Ultimo/Scripts_Test.php
Summary
Verification
Notes
aidevops.sh v3.31.0 plugin for OpenCode v1.17.12 with gpt-5.5 spent 1h 30m and 469,237 tokens on this with the user in an interactive session. Merged via PR #1596 to main. |
Summary
.wuboxearly-click guard inadmin_headwhen wubox is enqueued so modal form links cannot navigate to raw AJAX URLs before footer scripts load.Scripts_Testcoverage for the new hook and guard contents.Verification
vendor/bin/phpcs inc/class-scripts.php tests/WP_Ultimo/Scripts_Test.phpvendor/bin/phpunit --filter Scripts_Test.wuboxAdd Domain AJAX href: without guard the click navigated toadmin-ajax.php?action=wu_form_display&form=add_new_domain; with guard the URL stayed put and one click was queued.Notes
.wuboxclass, not only the domains page.aidevops.sh v3.31.0 plugin for OpenCode v1.17.12 with gpt-5.5 spent 1h 30m and 469,237 tokens on this with the user in an interactive session.
Summary by CodeRabbit
Bug Fixes
Refactor