Ticket #25073: 25073-8.patch
File 25073-8.patch, 3.7 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/misc.php
739 739 return $response; 740 740 } 741 741 add_filter( 'heartbeat_received', 'wp_refresh_post_nonces', 10, 3 ); 742 743 /** 744 * Disable suspending of Heartbeat on the Add/Edit Post screens 745 * 746 * @since 3.8 747 */ 748 function _disable_heartbeat_suspend( $settings ) { 749 global $pagenow; 750 751 if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { 752 $settings['suspend'] = 'disable'; 753 } 754 755 return $settings; 756 } 757 add_filter( 'heartbeat_settings', '_disable_heartbeat_suspend' ); -
src/wp-includes/js/heartbeat.js
34 34 var Heartbeat = function() { 35 35 var $document = $(document), 36 36 settings = { 37 // Used to stop the "beat"38 isRunning: true,37 // Suspend/resume 38 suspend: false, 39 39 40 // Whether suspending is enabled 41 suspendEnabled: true, 42 40 43 // Current screen id, defaults to the JS global 'pagenow' when present (in the admin) or 'front' 41 44 screenId: '', 42 45 … … 128 131 if ( ! settings.screenId ) { 129 132 settings.screenId = options.screenId || 'front'; 130 133 } 134 135 if ( options.suspend === 'disable' ) { 136 settings.suspendEnabled = false; 137 } 131 138 } 132 139 133 140 // Convert to milliseconds … … 145 152 focused(); 146 153 }).on( 'unload.wp-heartbeat', function() { 147 154 // Don't connect any more 148 settings.isRunning = false; 155 settings.suspend = true; 156 157 // Abort the last request if not completed 158 if ( settings.xhr && settings.xhr.readyState !== 4 ) { 159 settings.xhr.abort(); 160 } 149 161 }); 150 162 151 163 // Check for user activity every 30 seconds. … … 274 286 275 287 // If the connection to the server is slower than the interval, 276 288 // heartbeat connects as soon as the previous connection's response is received. 277 if ( settings.connecting ) {289 if ( settings.connecting || settings.suspend ) { 278 290 return; 279 291 } 280 292 … … 351 363 var delta = time() - settings.lastTick, 352 364 interval = settings.mainInterval; 353 365 354 if ( ! settings.isRunning) {366 if ( settings.suspend ) { 355 367 return; 356 368 } 357 369 … … 403 415 clearFocusTimers(); 404 416 settings.userActivity = time(); 405 417 418 // Resume if suspended 419 settings.suspend = false; 420 406 421 if ( ! settings.hasFocus ) { 407 422 settings.hasFocus = true; 408 423 scheduleNextTick(); … … 513 528 blurred(); 514 529 } 515 530 531 if ( settings.suspendEnabled && lastActive > 1800000 ) { 532 // Suspend after 30 min. of inactivity 533 settings.suspend = true; 534 } 535 516 536 if ( ! settings.userActivityEvents ) { 517 537 $document.on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active', function(){ userIsActive(); } ); 518 538 … … 562 582 } 563 583 564 584 /** 585 * Disable suspending 586 * 587 * Should be used only when Heartbeat is performing critical tasks like autosave, post-locking, etc. 588 * Using this for non-crittical tasks may overload the user's hosting account if several 589 * browser windows/tabs are left open for a long time. 590 * 591 * @return void 592 */ 593 function disableSuspend() { 594 settings.suspendEnabled = false; 595 } 596 597 /** 565 598 * Get/Set the interval 566 599 * 567 600 * When setting to 'fast' or 5, by default interval is 5 sec. for the next 30 ticks (for 2 min and 30 sec). … … 691 724 return { 692 725 hasFocus: hasFocus, 693 726 connectNow: connectNow, 727 disableSuspend: disableSuspend, 694 728 setInterval: setInterval, 695 729 hasConnectionError: hasConnectionError, 696 730 enqueue: enqueue,