Heartbeat: rename some vars/args to make them more intuitive, don't set user_id on every request, see #23216

git-svn-id: http://core.svn.wordpress.org/trunk@24406 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2013-06-05 00:13:40 +00:00
parent c0340f8188
commit 0fff739949
4 changed files with 26 additions and 29 deletions

View File

@ -13,10 +13,10 @@ function wp_ajax_nopriv_heartbeat() {
$response = array();
// screen_id is the same as $current_screen->id and the JS global 'pagenow'
if ( ! empty($_POST['screenid']) )
$screen_id = sanitize_key($_POST['screenid']);
if ( ! empty($_POST['screen_id']) )
$screen_id = sanitize_key($_POST['screen_id']);
else
$screen_id = 'site';
$screen_id = 'front';
if ( ! empty($_POST['data']) ) {
$data = wp_unslash( (array) $_POST['data'] );
@ -29,7 +29,7 @@ function wp_ajax_nopriv_heartbeat() {
do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
// send the current time according to the server
$response['servertime'] = time();
$response['server_time'] = time();
wp_send_json($response);
}
@ -2058,16 +2058,13 @@ function wp_ajax_heartbeat() {
$response = array();
// screen_id is the same as $current_screen->id and the JS global 'pagenow'
if ( ! empty($_POST['screenid']) )
$screen_id = sanitize_key($_POST['screenid']);
if ( ! empty($_POST['screen_id']) )
$screen_id = sanitize_key($_POST['screen_id']);
else
$screen_id = 'site';
$screen_id = 'front';
if ( ! empty($_POST['data']) ) {
$data = (array) $_POST['data'];
// todo: how much to sanitize and preset and what to leave to be accessed from $data or $_POST..?
$user = wp_get_current_user();
$data['user_id'] = $user->exists() ? $user->ID : 0;
// todo: separate filters: 'heartbeat_[action]' so we call different callbacks only when there is data for them,
// or all callbacks listen to one filter and run when there is something for them in $data?
@ -2080,7 +2077,7 @@ function wp_ajax_heartbeat() {
do_action( 'heartbeat_tick', $response, $screen_id );
// send the current time acording to the server
$response['servertime'] = time();
$response['server_time'] = time();
wp_send_json($response);
}

View File

@ -569,8 +569,8 @@ add_action('admin_head', '_ipad_meta');
function wp_check_locked_posts( $response, $data, $screen_id ) {
$checked = array();
if ( 'edit-post' == $screen_id && array_key_exists( 'wp-check-locked', $data ) && is_array( $data['wp-check-locked'] ) ) {
foreach ( $data['wp-check-locked'] as $key ) {
if ( 'edit-post' == $screen_id && array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) {
foreach ( $data['wp-check-locked-posts'] as $key ) {
$post_id = (int) substr( $key, 5 );
if ( current_user_can( 'edit_post', $post_id ) && ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) {
@ -585,7 +585,7 @@ function wp_check_locked_posts( $response, $data, $screen_id ) {
}
if ( ! empty( $checked ) )
$response['wp-check-locked'] = $checked;
$response['wp-check-locked-posts'] = $checked;
return $response;
}
@ -601,10 +601,10 @@ function wp_refresh_post_lock( $response, $data, $screen_id ) {
$received = $data['wp-refresh-post-lock'];
$send = array();
if ( !$post_id = absint( $received['post_id'] ) )
if ( ! $post_id = absint( $received['post_id'] ) )
return $response;
if ( !current_user_can('edit_post', $post_id) )
if ( ! current_user_can('edit_post', $post_id) )
return $response;
if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) {

View File

@ -293,8 +293,8 @@ inlineEditPost = {
$( document ).ready( function(){ inlineEditPost.init(); } );
// Show/hide locks on posts
$( document ).on( 'heartbeat-tick.wp-check-locked', function( e, data ) {
var locked = data['wp-check-locked'] || {};
$( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
var locked = data['wp-check-locked-posts'] || {};
$('#the-list tr').each( function(i, el) {
var key = el.id, row = $(el), lock_data, avatar;
@ -315,7 +315,7 @@ $( document ).on( 'heartbeat-tick.wp-check-locked', function( e, data ) {
row.find('.column-title .locked-avatar').empty();
}
});
}).on( 'heartbeat-send.wp-check-locked', function( e, data ) {
}).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) {
var check = [];
$('#the-list tr').each( function(i, el) {
@ -324,7 +324,7 @@ $( document ).on( 'heartbeat-tick.wp-check-locked', function( e, data ) {
});
if ( check.length )
data['wp-check-locked'] = check;
data['wp-check-locked-posts'] = check;
});
}(jQuery));

View File

@ -11,7 +11,7 @@ window.wp = window.wp || {};
running,
beat,
nonce,
screenid = typeof pagenow != 'undefined' ? pagenow : '',
screenId = typeof pagenow != 'undefined' ? pagenow : '',
url = typeof ajaxurl != 'undefined' ? ajaxurl : '',
settings,
tick = 0,
@ -42,17 +42,17 @@ window.wp = window.wp || {};
interval = settings.interval || 15; // default interval
delete settings.interval;
// The interval can be from 5 to 60 sec.
if ( interval < 5 )
interval = 5;
// The interval can be from 15 to 60 sec. and can be set temporarily to 5 sec.
if ( interval < 15 )
interval = 15;
else if ( interval > 60 )
interval = 60;
interval = interval * 1000;
// 'screenid' can be added from settings on the front-end where the JS global 'pagenow' is not set
screenid = screenid || settings.screenid || 'site';
delete settings.screenid;
// 'screenId' can be added from settings on the front-end where the JS global 'pagenow' is not set
screenId = screenId || settings.screenId || 'front';
delete settings.screenId;
// Add or overwrite public vars
$.extend( this, settings );
@ -83,7 +83,7 @@ window.wp = window.wp || {};
return false;
}
// Set error state and fire an event if XHR errors or timeout
// Set error state and fire an event on XHR errors or timeout
function errorstate( error ) {
var trigger;
@ -148,7 +148,7 @@ window.wp = window.wp || {};
send.interval = interval / 1000;
send._nonce = nonce;
send.action = 'heartbeat';
send.screenid = screenid;
send.screen_id = screenId;
send.has_focus = hasFocus;
connecting = true;