GH#707: fix(tours): use wp_add_inline_script on underscore to define wu_tours globals#708
Conversation
… globals wu_tours was localized onto wu-admin which is only enqueued on WP Ultimo pages (since PR #433). The network dashboard (dashboard-network) is not a WP Ultimo page, so wu-admin was absent there and the localization silently did nothing, leaving wu_tours undefined when tours.js executed. Fix: replace wp_localize_script('wu-admin', ...) with wp_add_inline_script() on 'underscore' — a WordPress core script always present in the admin. This injects wu_tours and wu_tours_vars as globals immediately after underscore loads, making them available to the wu-tours module regardless of whether wu-admin is enqueued. Add Tours_Test with 7 unit tests including a regression test that verifies wu_tours is defined via inline script on underscore (not localized on wu-admin). Closes #707
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 59 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 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: |
|
Performance Test Results Performance test results for 6daf954 are in 🛎️! Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown. URL:
|
Summary
wp_localize_script('wu-admin', 'wu_tours', ...)withwp_add_inline_script('underscore', ...)inTours::enqueue_scripts()underscoreis a WordPress core script always present in the admin;wu-adminis only enqueued on WP Ultimo pages (since PR Performance Audit #433)Tours_Testwith 7 unit tests including a regression test verifyingwu_toursis defined via inline script onunderscore(not localized onwu-admin)Problem
tours.jsline 7 calls_.each(wu_tours, ...)unconditionally.wu_tourswas localized ontowu-admin, but since PR #433 (cb5a40fd)wu-adminis only enqueued on pages wherewu_is_wu_page()returns true. The network dashboard (index.php, hook suffixdashboard-network) is not a WP Ultimo page, sowu-adminwas absent there and the localization silently did nothing, leavingwu_toursundefined whentours.jsexecuted.Fix
Use
wp_add_inline_script('underscore', ...)to injectwu_toursandwu_tours_varsas globals immediately afterunderscoreloads.underscoreis a WordPress core script always present in the admin — it is already being enqueued byTours::enqueue_scripts(). This decouples tours fromwu-adminbeing present, fixing the regression on the network dashboard.This is Option 1 from the issue: the architectural fix that addresses the root cause rather than just guarding the JS.
Files Changed
inc/ui/class-tours.php— replacewp_localize_scriptonwu-adminwithwp_add_inline_scriptonunderscoretests/WP_Ultimo/UI/Tours_Test.php— new: 7 unit tests forToursclassRuntime Testing
Risk level: Medium (script enqueuing, no payment/auth/data-deletion paths)
Self-assessed — the fix is a PHP-side script enqueuing change. The regression test (
test_enqueue_scripts_inlines_data_on_underscore_not_wu_admin) verifies the exact mechanism:wu_toursis attached tounderscoreviawp_add_inline_script, andwu-admindoes NOT havewu_tourslocalized onto it.All 7
Tours_Testtests pass. All 11Dashboard_Widgets_Testtests pass (no regressions).Related
wu_moment/activity-stream.js)aidevops.sh v3.5.463 plugin for OpenCode v1.3.0 with claude-sonnet-4-6