Skip to content

Commit

Permalink
Replace fetch with wp.ajax.post
Browse files Browse the repository at this point in the history
Fixes #125

This PR was written by AI and has not been reviewed yet for accuracy

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/WordPress/plugin-check/issues/125?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
chriscct7 committed Sep 17, 2024
1 parent c187c17 commit dacdd97
Showing 1 changed file with 29 additions and 64 deletions.
93 changes: 29 additions & 64 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,14 @@
* @param {Object} data Data object with props passed to form data.
*/
function setUpEnvironment( data ) {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append( 'plugin', data.plugin );
pluginCheckData.append(
'action',
pluginCheck.actionSetUpRuntimeEnvironment
);

for ( let i = 0; i < data.checks.length; i++ ) {
pluginCheckData.append( 'checks[]', data.checks[ i ] );
}

return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
body: pluginCheckData,
} )
.then( ( response ) => {
return response.json();
} )
const pluginCheckData = {
nonce: pluginCheck.nonce,
plugin: data.plugin,
action: pluginCheck.actionSetUpRuntimeEnvironment,
checks: data.checks

Check failure on line 125 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
};

return wp.ajax.post( pluginCheck.actionSetUpRuntimeEnvironment, pluginCheckData )

Check failure on line 128 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎↹↹↹`
.then( handleDataErrors )
.then( ( responseData ) => {
if ( ! responseData.data || ! responseData.data.message ) {
Expand All @@ -158,21 +146,12 @@
* @return {Object} The response data.
*/
function cleanUpEnvironment() {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append(
'action',
pluginCheck.actionCleanUpRuntimeEnvironment
);
const pluginCheckData = {
nonce: pluginCheck.nonce,
action: pluginCheck.actionCleanUpRuntimeEnvironment

Check failure on line 151 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
};

return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
body: pluginCheckData,
} )
.then( ( response ) => {
return response.json();
} )
return wp.ajax.post( pluginCheck.actionCleanUpRuntimeEnvironment, pluginCheckData )

Check failure on line 154 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `.post(·pluginCheck.actionCleanUpRuntimeEnvironment,·pluginCheckData·` with `⏎↹↹↹.post(⏎↹↹↹↹pluginCheck.actionCleanUpRuntimeEnvironment,⏎↹↹↹↹pluginCheckData⏎↹↹↹`
.then( handleDataErrors )
.then( ( responseData ) => {
if ( ! responseData.data || ! responseData.data.message ) {
Expand All @@ -189,28 +168,20 @@
* @since 1.0.0
*/
function getChecksToRun() {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append( 'plugin', pluginsList.value );
pluginCheckData.append( 'action', pluginCheck.actionGetChecksToRun );
const pluginCheckData = {
nonce: pluginCheck.nonce,
plugin: pluginsList.value,
action: pluginCheck.actionGetChecksToRun,
categories: []

Check failure on line 175 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
};

for ( let i = 0; i < categoriesList.length; i++ ) {
if ( categoriesList[ i ].checked ) {
pluginCheckData.append(
'categories[]',
categoriesList[ i ].value
);
pluginCheckData.categories.push( categoriesList[ i ].value );
}
}

return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
body: pluginCheckData,
} )
.then( ( response ) => {
return response.json();
} )
return wp.ajax.post( pluginCheck.actionGetChecksToRun, pluginCheckData )

Check failure on line 184 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎↹↹↹`
.then( handleDataErrors )
.then( ( responseData ) => {
if (
Expand Down Expand Up @@ -286,20 +257,14 @@
* @return {Object} The check results.
*/
function runCheck( plugin, check ) {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append( 'plugin', plugin );
pluginCheckData.append( 'checks[]', check );
pluginCheckData.append( 'action', pluginCheck.actionRunChecks );

return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
body: pluginCheckData,
} )
.then( ( response ) => {
return response.json();
} )
const pluginCheckData = {
nonce: pluginCheck.nonce,
plugin: plugin,

Check failure on line 262 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Expected property shorthand
checks: [ check ],
action: pluginCheck.actionRunChecks

Check failure on line 264 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
};

return wp.ajax.post( pluginCheck.actionRunChecks, pluginCheckData )

Check failure on line 267 in assets/js/plugin-check-admin.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎↹↹↹`
.then( handleDataErrors )
.then( ( responseData ) => {
// If the response is successful and there is no message in the response.
Expand Down

0 comments on commit dacdd97

Please sign in to comment.