WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/03/2013 07:03:27 AM (7 years ago)
Author:
azaozz
Message:

Heartbeat API: throttle down when the window looses focus or when the user is inactive, always send 'screen_id', change the interval settings to 'fast' (5sec), 'standard' (15sec) and 'slow' (60sec), the interval can be changed from PHP, see #23216

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ajax-actions.php

    r23355 r23382  
    20752075function wp_ajax_heartbeat() {
    20762076    check_ajax_referer( 'heartbeat-nonce', '_nonce' );
    2077     $response = array( 'pagenow' => '' );
    2078 
    2079     if ( ! empty($_POST['pagenow']) )
    2080         $response['pagenow'] = sanitize_key($_POST['pagenow']);
     2077    $response = array();
     2078
     2079    // screenid is the same as $current_screen->id and the JS global 'pagenow'
     2080    if ( ! empty($_POST['screenid']) )
     2081        $screen_id = sanitize_key($_POST['screenid']);
     2082    else
     2083        $screen_id = 'site';
    20812084   
    20822085    if ( ! empty($_POST['data']) ) {
     
    20882091        // todo: separate filters: 'heartbeat_[action]' so we call different callbacks only when there is data for them,
    20892092        // or all callbacks listen to one filter and run when there is something for them in $data?
    2090         $response = apply_filters( 'heartbeat_received', $response, $data );
    2091     }
    2092 
    2093     $response = apply_filters( 'heartbeat_send', $response );
     2093        $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id );
     2094    }
     2095
     2096    $response = apply_filters( 'heartbeat_send', $response, $screen_id );
    20942097
    20952098    // Allow the transport to be replaced with long-polling easily
    2096     do_action( 'heartbeat_tick', $response );
    2097 
    2098     // always send the current time acording to the server
    2099     $response['time'] = time();
     2099    do_action( 'heartbeat_tick', $response, $screen_id );
     2100
     2101    // send the current time acording to the server
     2102    $response['servertime'] = time();
     2103
     2104    // Change the interval, format: array( speed, ticks )
     2105    if ( isset($response['heartbeat_interval']) )
     2106        $response['heartbeat_interval'] = (array) $response['heartbeat_interval'];
    21002107
    21012108    wp_send_json($response);
Note: See TracChangeset for help on using the changeset viewer.