Make WordPress Core


Ignore:
Timestamp:
01/29/2013 06:15:25 AM (14 years ago)
Author:
azaozz
Message:

Heartbeat API: first run, see #23216

File:
1 edited

Legend:

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

    r23293 r23355  
    20722072        wp_send_json_success( $html );
    20732073}
     2074
     2075function wp_ajax_heartbeat() {
     2076        check_ajax_referer( 'heartbeat-nonce', '_nonce' );
     2077        $response = array( 'pagenow' => '' );
     2078
     2079        if ( ! empty($_POST['pagenow']) )
     2080                $response['pagenow'] = sanitize_key($_POST['pagenow']);
     2081       
     2082        if ( ! empty($_POST['data']) ) {
     2083                $data = (array) $_POST['data'];
     2084                // todo: how much to sanitize and preset and what to leave to be accessed from $data or $_POST..?
     2085                $user = wp_get_current_user();
     2086                $data['user_id'] = $user->exists() ? $user->ID : 0;
     2087
     2088                // todo: separate filters: 'heartbeat_[action]' so we call different callbacks only when there is data for them,
     2089                // 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 );
     2094
     2095        // 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();
     2100
     2101        wp_send_json($response);
     2102}
Note: See TracChangeset for help on using the changeset viewer.