Skip to content

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

Open
faisalahammad wants to merge 3 commits into
WordPress:trunkfrom
faisalahammad:fix/131-decouple-ajax
Open

fix(admin): decouple AJAX calls and remove unnecessary return values#1415
faisalahammad wants to merge 3 commits 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

github-actions Bot commented Jul 26, 2026

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: davidperezgar <davidperez@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Plugin Check admin “Check it!” flow to decouple the chained AJAX calls by passing explicit parameters between steps (instead of passing raw response payloads), and simplifies the PHP AJAX response surface accordingly.

Changes:

  • Refactored plugin-check-admin.js to pass explicit plugin, checks, types, and flags between getChecksToRun, setUpEnvironment, runChecks, and runCheck.
  • Added shared JS helpers (fetchAJAX, getSelectedValues) and updated exports to use the shared AJAX wrapper.
  • Simplified the PHP runtime setup endpoint by removing unnecessary returned plugin/checks values and making configure_runner() effectively void.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/Admin/Admin_AJAX.php Removes unused runner config return values and trims the runtime setup success payload to message only.
assets/js/plugin-check-admin.js Introduces fetchAJAX/getSelectedValues helpers and refactors the admin AJAX flow to use explicit arguments (including export requests).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread assets/js/plugin-check-admin.js
Update handleDataErrors to read the message from WP_Error array
responses and object responses alike, so export errors (which
return { message: ... }) no longer throw a TypeError.

Addresses PR feedback.

Refs WordPress#1415
@faisalahammad

Copy link
Copy Markdown
Contributor Author

Review fixes applied (commit b0d4609)

Addressed the Copilot review finding:

  • handleDataErrors() now reads the error message from both payload shapes. WP_Error responses serialize to an array (data.data[0].message), while plain-object payloads pass through as-is (data.data.message), matching the export_results() error response. Export failure no longer throws a TypeError and shows the server message instead.

Quality gates passed: wp-scripts lint-js, no CodeRabbit findings, manual testing confirmed by the author.

@davidperezgar

davidperezgar commented Aug 3, 2026

Copy link
Copy Markdown
Member

@faisalahammad Small documentation note: since getSelectedValues() and fetchAJAX() are newly introduced in this PR, could their @since tags be set to 2.1.0 instead of 1.0.0?

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

3 participants