-
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 #902 from WordPress/feature/creating-standalone-pl…
…ugins Merge `feature/creating-standalone-plugins` feature branch
- Loading branch information
Showing
6 changed files
with
959 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
( function ( $, document ) { | ||
$( document ).ajaxComplete( function( event, xhr, settings ) { | ||
// Check if this is the 'install-plugin' request. | ||
if ( settings.data && typeof settings.data === 'string' && settings.data.includes( 'action=install-plugin' ) ) { | ||
var params = new URLSearchParams( settings.data ); | ||
var slug = params.get('slug'); | ||
|
||
// Check if 'slug' was found and output the value. | ||
if ( ! slug ) { | ||
return; | ||
} | ||
|
||
var target_element = $( '.wpp-standalone-plugins a[data-slug="' + slug + '"]' ); | ||
if ( ! target_element ) { | ||
return; | ||
} | ||
|
||
/* | ||
* WordPress core uses a 1s timeout for updating the activation link, | ||
* so we set a 1.5 timeout here to ensure our changes get updated after | ||
* the core changes have taken place. | ||
*/ | ||
setTimeout( function() { | ||
var plugin_url = target_element.attr( 'href' ); | ||
if ( ! plugin_url ) { | ||
return; | ||
} | ||
var nonce = target_element.attr( 'data-plugin-activation-nonce' ); | ||
var plugin_slug = target_element.attr( 'data-slug' ); | ||
var url = new URL( plugin_url ); | ||
url.searchParams.set( 'action', 'perflab_activate_plugin' ); | ||
url.searchParams.set( '_wpnonce', nonce ); | ||
url.searchParams.set( 'plugin', plugin_slug ); | ||
target_element.attr( 'href', url.href ); | ||
}, 1500 ); | ||
} | ||
} ); | ||
} )( jQuery, document ); |
Oops, something went wrong.