mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Block Editor: Refresh nonces used by wp.apiFetch.
Adds heartbeat nonces refreshing support to `wp.apiFetch` requests. Props pento, adamsilverstein, dd32, desrosj, youknowriad. Merges [43939] into trunk. Fixes #45113. git-svn-id: https://develop.svn.wordpress.org/trunk@44275 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -351,6 +351,7 @@
|
||||
if ( trigger && ! hasConnectionError() ) {
|
||||
settings.connectionError = true;
|
||||
$document.trigger( 'heartbeat-connection-lost', [error, status] );
|
||||
wp.hooks.doAction( 'heartbeat.connection-lost', error, status );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,6 +373,7 @@
|
||||
settings.errorcount = 0;
|
||||
settings.connectionError = false;
|
||||
$document.trigger( 'heartbeat-connection-restored' );
|
||||
wp.hooks.doAction( 'heartbeat.connection-restored' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,6 +402,7 @@
|
||||
settings.queue = {};
|
||||
|
||||
$document.trigger( 'heartbeat-send', [ heartbeatData ] );
|
||||
wp.hooks.doAction( 'heartbeat.send', heartbeatData );
|
||||
|
||||
ajaxData = {
|
||||
data: heartbeatData,
|
||||
@@ -436,6 +439,7 @@
|
||||
|
||||
if ( response.nonces_expired ) {
|
||||
$document.trigger( 'heartbeat-nonces-expired' );
|
||||
wp.hooks.doAction( 'heartbeat.nonces-expired' );
|
||||
}
|
||||
|
||||
// Change the interval from PHP
|
||||
@@ -444,7 +448,21 @@
|
||||
delete response.heartbeat_interval;
|
||||
}
|
||||
|
||||
// Update the heartbeat nonce if set.
|
||||
if ( response.heartbeat_nonce && typeof window.heartbeatSettings === 'object' ) {
|
||||
window.heartbeatSettings.nonce = response.heartbeat_nonce;
|
||||
delete response.heartbeat_nonce;
|
||||
}
|
||||
|
||||
// Update the Rest API nonce if set and wp-api loaded.
|
||||
if ( response.rest_nonce && typeof window.wpApiSettings === 'object' ) {
|
||||
window.wpApiSettings.nonce = response.rest_nonce;
|
||||
// This nonce is required for api-fetch through heartbeat.tick.
|
||||
// delete response.rest_nonce;
|
||||
}
|
||||
|
||||
$document.trigger( 'heartbeat-tick', [response, textStatus, jqXHR] );
|
||||
wp.hooks.doAction( 'heartbeat.tick', response, textStatus, jqXHR );
|
||||
|
||||
// Do this last. Can trigger the next XHR if connection time > 5 sec. and newInterval == 'fast'.
|
||||
if ( newInterval ) {
|
||||
@@ -453,6 +471,7 @@
|
||||
}).fail( function( jqXHR, textStatus, error ) {
|
||||
setErrorState( textStatus || 'unknown', jqXHR.status );
|
||||
$document.trigger( 'heartbeat-error', [jqXHR, textStatus, error] );
|
||||
wp.hooks.doAction( 'heartbeat.error', jqXHR, textStatus, error );
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user