Heartbeat API: first run, see #23216

git-svn-id: https://develop.svn.wordpress.org/trunk@23355 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2013-01-29 06:15:25 +00:00
parent a38f0e16c5
commit 5edc6b2711
6 changed files with 232 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ $core_actions_post = array(
'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
'send-attachment-to-editor', 'save-attachment-order',
'send-attachment-to-editor', 'save-attachment-order', 'heartbeat',
);
// Register core Ajax calls.
+29
View File
@@ -2071,3 +2071,32 @@ function wp_ajax_send_link_to_editor() {
wp_send_json_success( $html );
}
function wp_ajax_heartbeat() {
check_ajax_referer( 'heartbeat-nonce', '_nonce' );
$response = array( 'pagenow' => '' );
if ( ! empty($_POST['pagenow']) )
$response['pagenow'] = sanitize_key($_POST['pagenow']);
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?
$response = apply_filters( 'heartbeat_received', $response, $data );
}
$response = apply_filters( 'heartbeat_send', $response );
// Allow the transport to be replaced with long-polling easily
do_action( 'heartbeat_tick', $response );
// always send the current time acording to the server
$response['time'] = time();
wp_send_json($response);
}