Heartbeat API: add nopriv actions, add JS 'heartbeat-send' event, see #23216
git-svn-id: http://core.svn.wordpress.org/trunk@23481 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e91f4bd35f
commit
9c2ebc4c60
|
@ -67,6 +67,7 @@ if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_po
|
||||||
add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
|
add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
|
||||||
|
|
||||||
add_action( 'wp_ajax_nopriv_autosave', 'wp_ajax_nopriv_autosave', 1 );
|
add_action( 'wp_ajax_nopriv_autosave', 'wp_ajax_nopriv_autosave', 1 );
|
||||||
|
add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
|
||||||
|
|
||||||
if ( is_user_logged_in() )
|
if ( is_user_logged_in() )
|
||||||
do_action( 'wp_ajax_' . $_REQUEST['action'] ); // Authenticated actions
|
do_action( 'wp_ajax_' . $_REQUEST['action'] ); // Authenticated actions
|
||||||
|
|
|
@ -2081,7 +2081,7 @@ function wp_ajax_heartbeat() {
|
||||||
check_ajax_referer( 'heartbeat-nonce', '_nonce' );
|
check_ajax_referer( 'heartbeat-nonce', '_nonce' );
|
||||||
$response = array();
|
$response = array();
|
||||||
|
|
||||||
// screenid is the same as $current_screen->id and the JS global 'pagenow'
|
// screen_id is the same as $current_screen->id and the JS global 'pagenow'
|
||||||
if ( ! empty($_POST['screenid']) )
|
if ( ! empty($_POST['screenid']) )
|
||||||
$screen_id = sanitize_key($_POST['screenid']);
|
$screen_id = sanitize_key($_POST['screenid']);
|
||||||
else
|
else
|
||||||
|
@ -2106,9 +2106,31 @@ function wp_ajax_heartbeat() {
|
||||||
// send the current time acording to the server
|
// send the current time acording to the server
|
||||||
$response['servertime'] = time();
|
$response['servertime'] = time();
|
||||||
|
|
||||||
// Change the interval, format: array( speed, ticks )
|
wp_send_json($response);
|
||||||
if ( isset($response['heartbeat_interval']) )
|
}
|
||||||
$response['heartbeat_interval'] = (array) $response['heartbeat_interval'];
|
|
||||||
|
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']);
|
||||||
|
else
|
||||||
|
$screen_id = 'site';
|
||||||
|
|
||||||
|
if ( ! empty($_POST['data']) ) {
|
||||||
|
$data = wp_unslash( (array) $_POST['data'] );
|
||||||
|
$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
|
||||||
|
|
||||||
|
// Allow the transport to be replaced with long-polling easily
|
||||||
|
do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
|
||||||
|
|
||||||
|
// send the current time acording to the server
|
||||||
|
$response['servertime'] = time();
|
||||||
|
|
||||||
wp_send_json($response);
|
wp_send_json($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2287,6 +2287,8 @@ function __checked_selected_helper( $helper, $current, $echo, $type ) {
|
||||||
* @return array $settings
|
* @return array $settings
|
||||||
*/
|
*/
|
||||||
function wp_heartbeat_settings( $settings ) {
|
function wp_heartbeat_settings( $settings ) {
|
||||||
|
if ( is_user_logged_in() )
|
||||||
$setting['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
|
$setting['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
|
||||||
|
|
||||||
return $setting;
|
return $setting;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ window.wp = window.wp || {};
|
||||||
tick = time();
|
tick = time();
|
||||||
|
|
||||||
data.data = $.extend( {}, queue );
|
data.data = $.extend( {}, queue );
|
||||||
|
$(document).trigger( 'heartbeat-send', [data.data] );
|
||||||
|
|
||||||
data.interval = interval / 1000;
|
data.interval = interval / 1000;
|
||||||
data._nonce = nonce;
|
data._nonce = nonce;
|
||||||
|
|
Loading…
Reference in New Issue