-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #920 from WordPress/load/migration-script-in-setti…
…ng-page Load migration script in plugin setting page
- Loading branch information
Showing
3 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
( function ( document ) { | ||
document.addEventListener( 'DOMContentLoaded', function () { | ||
document.addEventListener( 'click', function ( event ) { | ||
if ( | ||
event.target.classList.contains( | ||
'perflab-install-active-plugin' | ||
) | ||
) { | ||
const target = event.target; | ||
target.parentElement | ||
.querySelector( 'span' ) | ||
.classList.remove( 'hidden' ); | ||
|
||
const data = new FormData(); | ||
data.append( | ||
'action', | ||
'perflab_install_activate_standalone_plugins' | ||
); | ||
data.append( 'nonce', perflab_module_migration_notice.nonce ); | ||
|
||
fetch( perflab_module_migration_notice.ajaxurl, { | ||
method: 'POST', | ||
credentials: 'same-origin', | ||
body: data, | ||
} ) | ||
.then( function ( response ) { | ||
if ( ! response.ok ) { | ||
throw new Error( | ||
wp.i18n.__( 'Network response was not ok.', 'performance-lab' ) | ||
); | ||
} | ||
return response.json(); | ||
} ) | ||
.then( function ( result ) { | ||
target.parentElement | ||
.querySelector( 'span' ) | ||
.classList.add( 'hidden' ); | ||
if ( ! result.success ) { | ||
alert( result.data.errorMessage ); | ||
} | ||
window.location.reload(); | ||
} ) | ||
.catch( function ( error ) { | ||
alert( error.errorMessage ); | ||
window.location.reload(); | ||
} ); | ||
} | ||
} ); | ||
} ); | ||
} )( document ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters