Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/js/_enqueues/wp/heartbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@

// Timer that keeps track of how long needs to be waited before connecting to
// the server again.
beatTimer: 0
beatTimer: 0,

// Post lock window in milliseconds. Synced from PHP via heartbeat_settings.
// Used to calculate the background tab heartbeat interval.
// Default matches the wp_check_post_lock_window default of 150 seconds.
postLockWindow: 150000
};

/**
Expand All @@ -112,7 +117,7 @@
* @return {void}
*/
function initialize() {
var options, hidden, visibilityState, visibilitychange;
var options, hidden, visibilityState, visibilitychange, postLockWindow;

if ( typeof window.pagenow === 'string' ) {
settings.screenId = window.pagenow;
Expand Down Expand Up @@ -172,6 +177,14 @@
if ( options.suspension === 'disable' ) {
settings.suspendEnabled = false;
}

if ( options.post_lock_window ) {
postLockWindow = parseInt( options.post_lock_window, 10 );

if ( postLockWindow > 0 ) {
settings.postLockWindow = postLockWindow * 1000;
}
}
}

// Convert to milliseconds.
Expand Down Expand Up @@ -509,7 +522,11 @@
}

if ( ! settings.hasFocus ) {
interval = 120000; // 120 seconds. Post locks expire after 150 seconds.
// Fire 30 seconds before the post lock window expires so backgrounded
// tabs always refresh the lock in time. For the default 150s window this
// equals 120s, preserving existing behaviour. Floored at 5s for very
// short custom windows.
interval = Math.max( 5000, settings.postLockWindow - 30000 );
} else if ( settings.countdown > 0 && settings.tempInterval ) {
interval = settings.tempInterval;
settings.countdown--;
Expand Down
5 changes: 4 additions & 1 deletion src/wp-admin/includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ function wp_refresh_heartbeat_nonces( $response ) {
}

/**
* Disables suspension of Heartbeat on the Add/Edit Post screens.
* Disables suspension of Heartbeat and sets post lock data on the Add/Edit Post screens.
*
* @since 3.8.0
*
Expand All @@ -1348,6 +1348,9 @@ function wp_heartbeat_set_suspension( $settings ) {

if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
$settings['suspension'] = 'disable';

/** This filter is documented in wp-admin/includes/ajax-actions.php */
$settings['post_lock_window'] = apply_filters( 'wp_check_post_lock_window', 150 );
}

return $settings;
Expand Down
Loading