fix: use _ajax_nonce for network-activate AJAX handler (#836)#875
fix: use _ajax_nonce for network-activate AJAX handler (#836)#875superdav42 merged 2 commits intomainfrom
Conversation
The inline <script> in requirements_table.php was rendered as visible text because wu_get_template_contents() captures output via ob_start and injects it as innerHTML — browsers do not execute script tags inserted this way. Extract the click handler to assets/js/network-activate.js, enqueue it via wp_enqueue_script in register_scripts(), and pass the translated error string through wp_localize_script. Also fix the AJAX nonce handling: - Use _ajax_nonce parameter (WordPress standard convention) instead of the generic 'nonce' key which can conflict with server-side filtering - Move capability check before nonce check so unauthorized users get a meaningful 'Permission denied' error instead of an opaque 403 - Use check_ajax_referer with stop=false to return a JSON error on nonce failure instead of wp_die(-1) Resolves #836
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR updates the AJAX network activation flow to use WordPress AJAX naming conventions. The nonce is now read from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: |
|
Performance Test Results Performance test results for 5e5395f 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:
|
…all_network_activate)
dd9cec7 to
3ee7cc6
Compare
🔨 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: |
The setup wizard requirements table HTML passes through wp_kses() twice (field-note.php and default.php templates). The button element's kses allowlist only permitted disabled, name, and value — stripping type="button" and data-ajax-nonce from the Network Activate button. Without type="button", the click submits the parent form instead of triggering the AJAX handler. Without data-ajax-nonce, the JS reads undefined and the server rejects the request with bad-nonce. PR #875 correctly moved the JS to an external file and changed the nonce field to _ajax_nonce, but the button attributes were still stripped before reaching the browser.
The setup wizard requirements table HTML passes through wp_kses() twice (field-note.php and default.php templates). The button element's kses allowlist only permitted disabled, name, and value — stripping type="button" and data-ajax-nonce from the Network Activate button. Without type="button", the click submits the parent form instead of triggering the AJAX handler. Without data-ajax-nonce, the JS reads undefined and the server rejects the request with bad-nonce. PR #875 correctly moved the JS to an external file and changed the nonce field to _ajax_nonce, but the button attributes were still stripped before reaching the browser.
Summary
Follow-up to #871. The Network Activate button now fires correctly (inline
<script>moved to external file), but the AJAX request returned 403 because the nonce parameter namenoncewas not matching WordPress's standard_ajax_nonceconvention.Changes
assets/js/network-activate.js): send nonce as_ajax_nonce(WordPress standard), read fromdata-ajax-nonceattributeinc/admin-pages/class-setup-wizard-admin-page.php):current_user_can()check before nonce check — gives a meaningful "Permission denied" error instead of opaque 403check_ajax_referer('...', false, false)— thefalsesecond arg makes WordPress check both_ajax_nonceand_wpnoncefallbacks; thefalsethird arg preventswp_die(-1)so we return a JSON error insteadviews/wizards/setup/requirements_table.php):data-nonce→data-ajax-nonceTesting
Setup_Wizard_Admin_Page_Testpasses (37 tests, exit 0)Resolves #836
Summary by CodeRabbit
Release Notes