Skip to content

fix(admin): decouple AJAX calls and remove unnecessary return values - #1415

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/131-decouple-ajax
Open

fix(admin): decouple AJAX calls and remove unnecessary return values#1415
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:fix/131-decouple-ajax

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #131

Decouple the AJAX call chain in the JS admin so each step takes its own arguments instead of relying on raw response data from the previous step. Remove the now-unnecessary return values from the PHP endpoint.

Why?

The previous JS chain passed the full response data object from one step to the next, forcing PHP endpoints to echo back values they did not own. For example, set_up_environment returned plugin and checks only because the next step needed them. This made the flow harder to understand and maintain.

How?

  • Added a fetchAJAX(formData) wrapper to reduce repeated fetch boilerplate across 5 call sites.
  • Added a getSelectedValues(list) helper to read checked checkboxes from a NodeList.
  • Added a module-scoped currentChecks variable so check slugs are stored between getChecksToRun and runChecks.
  • Refactored getChecksToRun, setUpEnvironment, runChecks, and runCheck to accept individual parameters instead of a data object.
  • Removed plugin and checks from the set_up_environment response. configure_runner() now returns void.
  • Updated exportResults to use the shared fetchAJAX wrapper.

Testing Instructions

  1. Open Tools > Plugin Check, pick a plugin, click Check it!.
  2. Verify results appear as expected. No console errors.
  3. Open DevTools > Network, confirm all four AJAX calls return 200 and success: true.
  4. Check the plugin_check_set_up_environment response - it should contain only data.message (no data.plugin or data.checks).
  5. Click export buttons (CSV, JSON, CTRF, Markdown) - all should download files with the correct filenames.
  6. Test failure paths: no plugin selected, invalid nonce via console, subscriber role.

AI Usage Disclosure

  • This PR was created without the help of AI tools
  • This PR includes AI-assisted code or content

If AI tools were used, please describe how they were used:
Used AI-assisted development tools for code suggestions and refactoring patterns.

Screenshots or screencast

No UI changes. The plugin behaves identically before and after.

Open WordPress Playground Preview

Refactor the JavaScript AJAX chain so each step takes its own
parameters instead of relying on raw response data from the
previous step. Remove the now-unnecessary plugin and checks
keys from the set_up_environment AJAX response, and drop the
array return from configure_runner.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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.

Decouple AJAX calls in JS logic and remove unnecessary return values from AJAX endpoints

2 participants