fix(tours): fix wu_tours undefined error and ensure once-only display#1161
fix(tours): fix wu_tours undefined error and ensure once-only display#1161superdav42 wants to merge 1 commit intomainfrom
Conversation
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.
|
Warning Rate limit exceeded
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 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 ignored due to path filters (1)
📒 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 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:
|
Summary
Two bugs in the admin tour system fixed in a single commit.
1.
wu_tours is not defined— JS ReferenceError on checkout form editorenqueue_scripts()is hooked toin_admin_footer. By the time that hook fires, WordPress has already printed all<head>scripts, includingunderscore. Callingwp_add_inline_script('underscore', ...)after the script tag has been output is silently ignored, sowu_toursandwu_tours_varsare never defined whentours.min.jsexecutes.Fix: replace
wp_add_inline_script()withwp_print_inline_script_tag()called directly insidein_admin_footer. That hook fires beforeadmin_footer, which is where WordPress prints enqueued script modules — guaranteeingwu_toursis defined before the module runs. (wp_print_inline_script_tag()is available since WP 5.7; this code path already requires WP 6.5+ forwp_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 andmark_as_finishednever 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. TheURLSearchParamspayload is sent asapplication/x-www-form-urlencodedPOST, sowu_request()andcheck_ajax_referer()work without any PHP changes. Falls back to$.ajax()for browsers without beacon support.Files changed
inc/ui/class-tours.phpwp_add_inline_script→wp_print_inline_script_tagassets/js/tours.js$.ajax→sendBeaconwith$.ajaxfallbackassets/js/tours.min.jsTesting
wu_tour_checkout_form_editoruser setting (or use a fresh user).