Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace fetch with wp.ajax.post #639

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 37 additions & 65 deletions assets/js/plugin-check-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,15 @@
* @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,
};

return wp.ajax
.post( pluginCheck.actionSetUpRuntimeEnvironment, pluginCheckData )
.then( handleDataErrors )
.then( ( responseData ) => {
if ( ! responseData.data || ! responseData.data.message ) {
Expand All @@ -158,21 +147,16 @@
* @return {Object} The response data.
*/
function cleanUpEnvironment() {
const pluginCheckData = new FormData();
pluginCheckData.append( 'nonce', pluginCheck.nonce );
pluginCheckData.append(
'action',
pluginCheck.actionCleanUpRuntimeEnvironment
);

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

return wp.ajax
.post(
pluginCheck.actionCleanUpRuntimeEnvironment,
pluginCheckData
)
.then( handleDataErrors )
.then( ( responseData ) => {
if ( ! responseData.data || ! responseData.data.message ) {
Expand All @@ -189,28 +173,21 @@
* @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: [],
};

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 )
.then( handleDataErrors )
.then( ( responseData ) => {
if (
Expand Down Expand Up @@ -286,20 +263,15 @@
* @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,
checks: [ check ],
action: pluginCheck.actionRunChecks,
};

return wp.ajax
.post( pluginCheck.actionRunChecks, pluginCheckData )
.then( handleDataErrors )
.then( ( responseData ) => {
// If the response is successful and there is no message in the response.
Expand Down