WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/25/2013 02:32:22 AM (8 years ago)
Author:
azaozz
Message:

Heartbeat API: add nopriv actions, add JS 'heartbeat-send' event, see #23216

File:
1 edited

Legend:

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

    r23416 r23481  
    20822082    $response = array();
    20832083
    2084     // screenid is the same as $current_screen->id and the JS global 'pagenow'
     2084    // screen_id is the same as $current_screen->id and the JS global 'pagenow'
    20852085    if ( ! empty($_POST['screenid']) )
    20862086        $screen_id = sanitize_key($_POST['screenid']);
    20872087    else
    20882088        $screen_id = 'site';
    2089    
     2089
    20902090    if ( ! empty($_POST['data']) ) {
    20912091        $data = wp_unslash( (array) $_POST['data'] );
     
    21072107    $response['servertime'] = time();
    21082108
    2109     // Change the interval, format: array( speed, ticks )
    2110     if ( isset($response['heartbeat_interval']) )
    2111         $response['heartbeat_interval'] = (array) $response['heartbeat_interval'];
    2112 
    21132109    wp_send_json($response);
    21142110}
     2111
     2112function wp_ajax_nopriv_heartbeat() {
     2113    $response = array();
     2114
     2115    // screen_id is the same as $current_screen->id and the JS global 'pagenow'
     2116    if ( ! empty($_POST['screenid']) )
     2117        $screen_id = sanitize_key($_POST['screenid']);
     2118    else
     2119        $screen_id = 'site';
     2120
     2121    if ( ! empty($_POST['data']) ) {
     2122        $data = wp_unslash( (array) $_POST['data'] );
     2123        $response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
     2124    }
     2125
     2126    $response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
     2127
     2128    // Allow the transport to be replaced with long-polling easily
     2129    do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
     2130
     2131    // send the current time acording to the server
     2132    $response['servertime'] = time();
     2133
     2134    wp_send_json($response);
     2135}
     2136
Note: See TracChangeset for help on using the changeset viewer.