Refresh nonce via heartbeats [MAILPOET-2839]
This commit is contained in:
@ -15,6 +15,14 @@ function requestFailed(errorMessage, xhr) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renew MailPoet nonce via heartbeats to keep auth
|
||||||
|
// for AJAX requests on long-open pages
|
||||||
|
jQuery(document).on('heartbeat-tick.mailpoet-ajax', (event, data) => {
|
||||||
|
if (data.mailpoet_token) {
|
||||||
|
window.mailpoet_token = data.mailpoet_token;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
version: 0.5,
|
version: 0.5,
|
||||||
options: {},
|
options: {},
|
||||||
|
@ -84,6 +84,12 @@ class API {
|
|||||||
'wp_ajax_nopriv_mailpoet',
|
'wp_ajax_nopriv_mailpoet',
|
||||||
[$this, 'setupAjax']
|
[$this, 'setupAjax']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// nonce refreshing via heartbeats
|
||||||
|
WPFunctions::get()->addAction(
|
||||||
|
'wp_refresh_nonces',
|
||||||
|
[$this, 'addTokenToHeartbeatResponse']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setupAjax() {
|
public function setupAjax() {
|
||||||
@ -234,6 +240,11 @@ class API {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addTokenToHeartbeatResponse($response) {
|
||||||
|
$response['mailpoet_token'] = Security::generateToken();
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
public function addEndpointNamespace($namespace, $version) {
|
public function addEndpointNamespace($namespace, $version) {
|
||||||
if (!empty($this->endpointNamespaces[$version][$namespace])) return;
|
if (!empty($this->endpointNamespaces[$version][$namespace])) return;
|
||||||
$this->endpointNamespaces[$version][] = $namespace;
|
$this->endpointNamespaces[$version][] = $namespace;
|
||||||
|
Reference in New Issue
Block a user