Skip to content

fix(tours): fix wu_tours undefined error and ensure once-only display#1161

Open
superdav42 wants to merge 1 commit intomainfrom
fix/tours-inline-data-and-beacon
Open

fix(tours): fix wu_tours undefined error and ensure once-only display#1161
superdav42 wants to merge 1 commit intomainfrom
fix/tours-inline-data-and-beacon

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Two bugs in the admin tour system fixed in a single commit.

1. wu_tours is not defined — JS ReferenceError on checkout form editor

enqueue_scripts() is hooked to in_admin_footer. By the time that hook fires, WordPress has already printed all <head> scripts, including underscore. Calling wp_add_inline_script('underscore', ...) after the script tag has been output is silently ignored, so wu_tours and wu_tours_vars are never defined when tours.min.js executes.

Fix: replace wp_add_inline_script() with wp_print_inline_script_tag() called directly inside in_admin_footer. That hook fires before admin_footer, which is where WordPress prints enqueued script modules — guaranteeing wu_tours is defined before the module runs. (wp_print_inline_script_tag() is available since WP 5.7; this code path already requires WP 6.5+ for wp_enqueue_script_module.)

2. Tour re-shows after first completion (shows twice instead of once)

markTourFinished() used a fire-and-forget $.ajax(). When the user clicks Close on the final step, Shepherd removes the tour overlay immediately. If the user refreshes before the async request completes, the browser cancels the in-flight request and mark_as_finished never runs — the setting is never written, so the tour appears again on the next load.

Fix: switch to navigator.sendBeacon(), which queues delivery at the OS/browser level and survives page navigation/unload. The URLSearchParams payload is sent as application/x-www-form-urlencoded POST, so wu_request() and check_ajax_referer() work without any PHP changes. Falls back to $.ajax() for browsers without beacon support.

Files changed

File Change
inc/ui/class-tours.php wp_add_inline_scriptwp_print_inline_script_tag
assets/js/tours.js $.ajaxsendBeacon with $.ajax fallback
assets/js/tours.min.js same, minified

Testing

  1. Clear the wu_tour_checkout_form_editor user setting (or use a fresh user).
  2. Visit Network Admin → Checkout Forms → Edit any form.
  3. Confirm tour appears with no JS console errors.
  4. Click through all steps and close the tour.
  5. Immediately refresh — tour should not reappear.

Two bugs in the admin tour system:

1. wu_tours is not defined (JS ReferenceError on checkout form editor)
   enqueue_scripts() is hooked to in_admin_footer, but by that point
   the <head> scripts (including 'underscore') have already been printed
   by WordPress. Calling wp_add_inline_script('underscore', ...) after
   the script tag has been output is silently ignored, so wu_tours and
   wu_tours_vars are never defined when tours.min.js executes.

   Fix: use wp_print_inline_script_tag() directly inside in_admin_footer.
   That hook fires before admin_footer, which is where WordPress prints
   enqueued script modules — guaranteeing wu_tours is defined first.

2. Tour re-shows after first completion (shows twice instead of once)
   markTourFinished() used a fire-and-forget $.ajax() call. When the
   user clicks Close on the last step, Shepherd removes the tour overlay
   immediately. If the user refreshes before the async request gets a
   response, the browser cancels the in-flight request and mark_as_finished
   never runs — the setting is never saved.

   Fix: use navigator.sendBeacon() which queues delivery at the OS/browser
   level and survives page navigation/unload. URLSearchParams payload is
   sent as application/x-www-form-urlencoded POST so wu_request() and
   check_ajax_referer() work without PHP-side changes. Falls back to
   $.ajax() for browsers without sendBeacon support.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

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

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: df806dd1-7c76-47ed-a1b3-dccae4090e22

📥 Commits

Reviewing files that changed from the base of the PR and between 55560d7 and c6edada.

⛔ Files ignored due to path filters (1)
  • assets/js/tours.min.js is excluded by !**/*.min.js
📒 Files selected for processing (2)
  • assets/js/tours.js
  • inc/ui/class-tours.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tours-inline-data-and-beacon

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

github-actions Bot commented May 7, 2026

🔨 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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Performance Test Results

Performance test results for 5744981 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.73 MB 844.00 ms 164.00 ms (+4.00 ms / +2% ) 1105.50 ms (+46.50 ms / +4% ) 2112.00 ms 2020.50 ms (+48.80 ms / +2% ) 92.80 ms (-2.60 ms / -3% )
1 56 49.12 MB 958.50 ms 154.00 ms (+4.50 ms / +3% ) 1118.50 ms 2146.00 ms 2057.25 ms 84.80 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.

1 participant