Changeset 26428
- Timestamp:
- 11/27/2013 01:55:59 AM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/misc.php
r26406 r26428 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 wp_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', 'wp_disable_heartbeat_suspend' ); -
trunk/src/wp-includes/js/heartbeat.js
r26276 r26428 35 35 var $document = $(document), 36 36 settings = { 37 // Used to stop the "beat" 38 isRunning: true, 37 // Suspend/resume 38 suspend: false, 39 40 // Whether suspending is enabled 41 suspendEnabled: true, 39 42 40 43 // Current screen id, defaults to the JS global 'pagenow' when present (in the admin) or 'front' … … 128 131 if ( ! settings.screenId ) { 129 132 settings.screenId = options.screenId || 'front'; 133 } 134 135 if ( options.suspend === 'disable' ) { 136 settings.suspendEnabled = false; 130 137 } 131 138 } … … 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 … … 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 } … … 352 364 interval = settings.mainInterval; 353 365 354 if ( ! settings.isRunning) {366 if ( settings.suspend ) { 355 367 return; 356 368 } … … 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; … … 514 529 } 515 530 531 if ( settings.suspendEnabled && lastActive > 1200000 ) { 532 // Suspend after 20 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(); } ); … … 560 580 settings.lastTick = 0; 561 581 scheduleNextTick(); 582 } 583 584 /** 585 * Disable suspending 586 * 587 * Should be used only when Heartbeat is performing critical tasks like autosave, post-locking, etc. 588 * Using this on many screens 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; 562 595 } 563 596 … … 692 725 hasFocus: hasFocus, 693 726 connectNow: connectNow, 727 disableSuspend: disableSuspend, 694 728 setInterval: setInterval, 695 729 hasConnectionError: hasConnectionError,
Note: See TracChangeset
for help on using the changeset viewer.