WordPress.org

Make WordPress Core

Changeset 23355


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

Heartbeat API: first run, see #23216

Location:
trunk
Files:
1 added
5 edited

Legend:

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

    r22967 r23355  
    5757    'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    5858    'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    59     'send-attachment-to-editor', 'save-attachment-order',
     59    'send-attachment-to-editor', 'save-attachment-order', 'heartbeat',
    6060);
    6161
  • 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}
  • trunk/wp-includes/default-filters.php

    r23329 r23355  
    291291add_filter( 'default_option_embed_autourls', '__return_true' );
    292292
     293// Default settings for heartbeat
     294add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
     295
    293296unset($filter, $action);
  • trunk/wp-includes/general-template.php

    r22634 r23355  
    22852285    return $result;
    22862286}
     2287
     2288/**
     2289 * Default settings for heartbeat
     2290 *
     2291 * Outputs the nonce used in the heartbeat XHR
     2292 *
     2293 * @since 3.6.0
     2294 *
     2295 * @param array $settings
     2296 * @return array $settings
     2297 */
     2298function wp_heartbeat_settings( $settings ) {
     2299    $setting['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
     2300    return $setting;
     2301}
  • trunk/wp-includes/script-loader.php

    r23339 r23355  
    108108
    109109    $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), false, 1 );
     110   
     111    $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array('jquery'), false, 1 );
     112    did_action( 'init' ) && $scripts->localize( 'heartbeat', 'heartbeatSettings',
     113        apply_filters( 'heartbeat_settings', array() )
     114    );
    110115
    111116    $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 );
     
    372377        $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 );
    373378
    374         $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 );
     379        $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox', 'heartbeat'), false, 1 );
    375380        did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
    376381            'ok' => __('OK'),
Note: See TracChangeset for help on using the changeset viewer.