Make WordPress Core

Changeset 23481


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

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

Location:
trunk
Files:
4 edited

Legend:

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

    r23355 r23481  
    6868
    6969add_action( 'wp_ajax_nopriv_autosave', 'wp_ajax_nopriv_autosave', 1 );
     70add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
    7071
    7172if ( is_user_logged_in() )
  • 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
  • trunk/wp-includes/general-template.php

    r23401 r23481  
    22882288 */
    22892289function wp_heartbeat_settings( $settings ) {
    2290         $setting['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
     2290        if ( is_user_logged_in() )
     2291                $setting['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
     2292
    22912293        return $setting;
    22922294}
  • trunk/wp-includes/js/heartbeat.js

    r23389 r23481  
    9696
    9797                        data.data = $.extend( {}, queue );
     98                        $(document).trigger( 'heartbeat-send', [data.data] );
    9899
    99100                        data.interval = interval / 1000;
Note: See TracChangeset for help on using the changeset viewer.