diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index d313854532..89d7cd3acf 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -66,7 +66,6 @@ if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) 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_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 ); if ( is_user_logged_in() ) diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 3724bfe9ef..648ff744b0 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -9,20 +9,29 @@ /* * No-privilege Ajax handlers. */ +function wp_ajax_nopriv_heartbeat() { + $response = array(); -function wp_ajax_nopriv_autosave() { - $id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; + // 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 ( ! $id ) - wp_die( -1 ); + if ( ! empty($_POST['data']) ) { + $data = wp_unslash( (array) $_POST['data'] ); + $response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id ); + } - $message = sprintf( __('ALERT: You are logged out! Could not save draft. Please log in again.'), wp_login_url() ); - $x = new WP_Ajax_Response( array( - 'what' => 'autosave', - 'id' => $id, - 'data' => $message - ) ); - $x->send(); + $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 according to the server + $response['servertime'] = time(); + + wp_send_json($response); } /* @@ -2098,31 +2107,6 @@ function wp_ajax_heartbeat() { wp_send_json($response); } -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); -} - function wp_ajax_revisions_data() { check_ajax_referer( 'revisions-ajax-nonce', 'nonce' );