mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
Nonce refresh:
- Update the heartbeat nonce when refreshing nonces on the Edit Post screen. - After a user logs in from the auth-check dialog, speed up heatrbeat to check/refresh nonces on the Edit Post screen. - Speeding up heartbeat: bring back the setting how long it should last (how many ticks). - Add 'heartbeat-nonces-expired' jQuery event when nonces have expired and the user is logged in. See #23295, see #23216. git-svn-id: https://develop.svn.wordpress.org/trunk@24528 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -10,7 +10,6 @@ window.wp = window.wp || {};
|
||||
var self = this,
|
||||
running,
|
||||
beat,
|
||||
nonce,
|
||||
screenId = typeof pagenow != 'undefined' ? pagenow : '',
|
||||
url = typeof ajaxurl != 'undefined' ? ajaxurl : '',
|
||||
settings,
|
||||
@@ -30,15 +29,13 @@ window.wp = window.wp || {};
|
||||
this.autostart = true;
|
||||
this.connectionLost = false;
|
||||
|
||||
if ( typeof( window.heartbeatSettings ) != 'undefined' ) {
|
||||
settings = window.heartbeatSettings;
|
||||
if ( typeof( window.heartbeatSettings ) == 'object' ) {
|
||||
settings = $.extend( {}, window.heartbeatSettings );
|
||||
|
||||
// Add private vars
|
||||
nonce = settings.nonce || '';
|
||||
delete settings.nonce;
|
||||
|
||||
url = settings.ajaxurl || url;
|
||||
delete settings.ajaxurl;
|
||||
delete settings.nonce;
|
||||
|
||||
interval = settings.interval || 15; // default interval
|
||||
delete settings.interval;
|
||||
@@ -120,7 +117,8 @@ window.wp = window.wp || {};
|
||||
}
|
||||
|
||||
function connect() {
|
||||
var send = {}, data, i, empty = true;
|
||||
var send = {}, data, i, empty = true,
|
||||
nonce = typeof window.heartbeatSettings == 'object' ? window.heartbeatSettings.nonce : '';
|
||||
tick = time();
|
||||
|
||||
data = $.extend( {}, queue );
|
||||
@@ -168,6 +166,11 @@ window.wp = window.wp || {};
|
||||
if ( self.connectionLost )
|
||||
errorstate();
|
||||
|
||||
if ( response.nonces_expired ) {
|
||||
$(document).trigger( 'heartbeat-nonces-expired' );
|
||||
return;
|
||||
}
|
||||
|
||||
// Change the interval from PHP
|
||||
if ( response.heartbeat_interval ) {
|
||||
new_interval = response.heartbeat_interval;
|
||||
@@ -334,16 +337,19 @@ window.wp = window.wp || {};
|
||||
* If the window doesn't have focus, the interval slows down to 2 min.
|
||||
*
|
||||
* @param string speed Interval speed: 'fast' (5sec), 'standard' (15sec) default, 'slow' (60sec)
|
||||
* @param string ticks Used with speed = 'fast', how many ticks before the speed reverts back
|
||||
* @return int Current interval in seconds
|
||||
*/
|
||||
this.interval = function( speed ) {
|
||||
this.interval = function( speed, ticks ) {
|
||||
var reset, seconds;
|
||||
ticks = parseInt( ticks, 10 ) || 30;
|
||||
ticks = ticks < 1 || ticks > 30 ? 30 : ticks;
|
||||
|
||||
if ( speed ) {
|
||||
switch ( speed ) {
|
||||
case 'fast':
|
||||
seconds = 5;
|
||||
countdown = 30;
|
||||
countdown = ticks;
|
||||
break;
|
||||
case 'slow':
|
||||
seconds = 60;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Interim login dialog
|
||||
(function($){
|
||||
var wrap, check, timeout;
|
||||
var wrap, check, scheduleTimeout, hideTimeout;
|
||||
|
||||
function show() {
|
||||
var parent = $('#wp-auth-check'), form = $('#wp-auth-check-form'), noframe = wrap.find('.wp-auth-fallback-expired'), frame, loaded = false;
|
||||
@@ -32,7 +32,7 @@
|
||||
height += 35;
|
||||
parent.find('.wp-auth-check-close').show();
|
||||
wrap.data('logged-in', 1);
|
||||
setTimeout( function() { hide(); }, 3000 );
|
||||
hideTimeout = setTimeout( function() { hide(); }, 3000 );
|
||||
}
|
||||
|
||||
parent.css( 'max-height', height + 60 + 'px' );
|
||||
@@ -62,6 +62,14 @@
|
||||
|
||||
function hide() {
|
||||
$(window).off( 'beforeunload.wp-auth-check' );
|
||||
window.clearTimeout( hideTimeout );
|
||||
|
||||
// When on the Edit Post screen, speed up heartbeat after the user logs in to quickly refresh nonces
|
||||
if ( typeof adminpage != 'undefined' && ( adminpage == 'post-php' || adminpage == 'post-new-php' )
|
||||
&& typeof wp != 'undefined' && wp.heartbeat ) {
|
||||
|
||||
wp.heartbeat.interval( 'fast', 1 );
|
||||
}
|
||||
|
||||
wrap.fadeOut( 200, function() {
|
||||
wrap.addClass('hidden').css('display', '').find('.wp-auth-check-close').css('display', '');
|
||||
@@ -71,8 +79,8 @@
|
||||
|
||||
function schedule() {
|
||||
check = false;
|
||||
window.clearTimeout( timeout );
|
||||
timeout = window.setTimeout( function(){ check = 1; }, 180000 ); // 3 min.
|
||||
window.clearTimeout( scheduleTimeout );
|
||||
scheduleTimeout = window.setTimeout( function(){ check = 1; }, 300000 ); // 5 min.
|
||||
}
|
||||
|
||||
$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
|
||||
|
||||
Reference in New Issue
Block a user