Make WordPress Core

Ticket #25073: 25073-8.patch

File 25073-8.patch, 3.7 KB (added by azaozz, 11 years ago)
  • src/wp-admin/includes/misc.php

     
    739739        return $response;
    740740}
    741741add_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 */
     748function _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}
     757add_filter( 'heartbeat_settings', '_disable_heartbeat_suspend' );
  • src/wp-includes/js/heartbeat.js

     
    3434        var Heartbeat = function() {
    3535                var $document = $(document),
    3636                        settings = {
    37                                 // Used to stop the "beat"
    38                                 isRunning: true,
     37                                // Suspend/resume
     38                                suspend: false,
    3939
     40                                // Whether suspending is enabled
     41                                suspendEnabled: true,
     42
    4043                                // Current screen id, defaults to the JS global 'pagenow' when present (in the admin) or 'front'
    4144                                screenId: '',
    4245
     
    128131                                if ( ! settings.screenId ) {
    129132                                        settings.screenId = options.screenId || 'front';
    130133                                }
     134
     135                                if ( options.suspend === 'disable' ) {
     136                                        settings.suspendEnabled = false;
     137                                }
    131138                        }
    132139
    133140                        // Convert to milliseconds
     
    145152                                focused();
    146153                        }).on( 'unload.wp-heartbeat', function() {
    147154                                // 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                                }
    149161                        });
    150162
    151163                        // Check for user activity every 30 seconds.
     
    274286
    275287                        // If the connection to the server is slower than the interval,
    276288                        // heartbeat connects as soon as the previous connection's response is received.
    277                         if ( settings.connecting ) {
     289                        if ( settings.connecting || settings.suspend ) {
    278290                                return;
    279291                        }
    280292
     
    351363                        var delta = time() - settings.lastTick,
    352364                                interval = settings.mainInterval;
    353365
    354                         if ( ! settings.isRunning ) {
     366                        if ( settings.suspend ) {
    355367                                return;
    356368                        }
    357369
     
    403415                        clearFocusTimers();
    404416                        settings.userActivity = time();
    405417
     418                        // Resume if suspended
     419                        settings.suspend = false;
     420
    406421                        if ( ! settings.hasFocus ) {
    407422                                settings.hasFocus = true;
    408423                                scheduleNextTick();
     
    513528                                blurred();
    514529                        }
    515530
     531                        if ( settings.suspendEnabled && lastActive > 1800000 ) {
     532                                // Suspend after 30 min. of inactivity
     533                                settings.suspend = true;
     534                        }
     535
    516536                        if ( ! settings.userActivityEvents ) {
    517537                                $document.on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active', function(){ userIsActive(); } );
    518538
     
    562582                }
    563583
    564584                /**
     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                /**
    565598                 * Get/Set the interval
    566599                 *
    567600                 * When setting to 'fast' or 5, by default interval is 5 sec. for the next 30 ticks (for 2 min and 30 sec).
     
    691724                return {
    692725                        hasFocus: hasFocus,
    693726                        connectNow: connectNow,
     727                        disableSuspend: disableSuspend,
    694728                        setInterval: setInterval,
    695729                        hasConnectionError: hasConnectionError,
    696730                        enqueue: enqueue,