Skip to content

GH#707: fix(tours): use wp_add_inline_script on underscore to define wu_tours globals#708

Merged
superdav42 merged 1 commit into
mainfrom
bugfix/fix-tours-wu-tours-undefined
Mar 30, 2026
Merged

GH#707: fix(tours): use wp_add_inline_script on underscore to define wu_tours globals#708
superdav42 merged 1 commit into
mainfrom
bugfix/fix-tours-wu-tours-undefined

Conversation

@superdav42

Copy link
Copy Markdown
Collaborator

Summary

  • Replace wp_localize_script('wu-admin', 'wu_tours', ...) with wp_add_inline_script('underscore', ...) in Tours::enqueue_scripts()
  • underscore is a WordPress core script always present in the admin; wu-admin is only enqueued on WP Ultimo pages (since PR Performance Audit #433)
  • Add Tours_Test with 7 unit tests including a regression test verifying wu_tours is defined via inline script on underscore (not localized on wu-admin)

Problem

tours.js line 7 calls _.each(wu_tours, ...) unconditionally. wu_tours was localized onto wu-admin, but since PR #433 (cb5a40fd) wu-admin is only enqueued on pages where wu_is_wu_page() returns true. The network dashboard (index.php, hook suffix 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.

Uncaught ReferenceError: wu_tours is not defined
    at HTMLDocument.<anonymous> (tours.js:7:10)

Fix

Use wp_add_inline_script('underscore', ...) to inject wu_tours and wu_tours_vars as globals immediately after underscore loads. underscore is a WordPress core script always present in the admin — it is already being enqueued by Tours::enqueue_scripts(). This decouples tours from wu-admin being 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 — replace wp_localize_script on wu-admin with wp_add_inline_script on underscore
  • tests/WP_Ultimo/UI/Tours_Test.php — new: 7 unit tests for Tours class

Runtime 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_tours is attached to underscore via wp_add_inline_script, and wu-admin does NOT have wu_tours localized onto it.

All 7 Tours_Test tests pass. All 11 Dashboard_Widgets_Test tests pass (no regressions).

Related


aidevops.sh v3.5.463 plugin for OpenCode v1.3.0 with claude-sonnet-4-6

… 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
@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 59 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7ae4c401-8e97-4de6-b769-3cc44cbe41a9

📥 Commits

Reviewing files that changed from the base of the PR and between f470a73 and 4e4e991.

📒 Files selected for processing (2)
  • inc/ui/class-tours.php
  • tests/WP_Ultimo/UI/Tours_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/fix-tours-wu-tours-undefined

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.

@github-actions

Copy link
Copy Markdown

🔨 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!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit c3c373e into main Mar 30, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown

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: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 (-1 / -3% ) 37.78 MB 866.00 ms (-40.50 ms / -5% ) 167.00 ms 1067.50 ms (-30.50 ms / -3% ) 2052.00 ms 1955.05 ms 91.30 ms (-3.25 ms / -4% )
1 56 49.01 MB 951.00 ms 145.50 ms (-4.00 ms / -3% ) 1101.00 ms 2036.00 ms (-64.00 ms / -3% ) 1956.50 ms (-61.20 ms / -3% ) 83.60 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tours): wu_tours is not defined on network dashboard

1 participant