wp_ajax_nopriv_heartbeat

The timeline below displays how wordpress function wp_ajax_nopriv_heartbeat has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Handles the Heartbeat API in the no-privilege context via AJAX .
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array  $response  The no-priv Heartbeat response.
         * @param array  $data      The $_POST data sent.
         * @param string $screen_id The screen ID.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 5.7

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array  $response  The no-priv Heartbeat response.
         * @param array  $data      The $_POST data sent.
         * @param string $screen_id The screen ID.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 5.5

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array  $response  The no-priv Heartbeat response.
         * @param array  $data      The $_POST data sent.
         * @param string $screen_id The screen ID.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen ID.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 5.4

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array  $response  The no-priv Heartbeat response.
         * @param array  $data      The $_POST data sent.
         * @param string $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 5.1

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array  $response  The no-priv Heartbeat response.
         * @param array  $data      The $_POST data sent.
         * @param string $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array  $response  The no-priv Heartbeat response.
     * @param string $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 4.6

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filters Heartbeat Ajax response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array|object $response  The no-priv Heartbeat response object or array.
         * @param array        $data      An array of data passed via $_POST.
         * @param string       $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filters Heartbeat Ajax response when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The Heartbeat response object or array.
     * @param string       $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The no-priv Heartbeat response.
     * @param string       $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 4.4

/**
 * Administration API: Core Ajax handlers
 *
 * @package WordPress
 * @subpackage Administration
 * @since 2.1.0
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filter Heartbeat AJAX response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array|object $response  The no-priv Heartbeat response object or array.
         * @param array        $data      An array of data passed via $_POST.
         * @param string       $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filter Heartbeat AJAX response when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The Heartbeat response object or array.
     * @param string       $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The no-priv Heartbeat response.
     * @param string       $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 4.0

/**
 * WordPress Core Ajax Handlers.
 *
 * @package WordPress
 * @subpackage Administration
 */
//
// No-privilege Ajax handlers.
//
/**
 * Ajax handler for the Heartbeat API in
 * the no-privilege context.
 *
 * Runs when the user is not logged in.
 *
 * @since 3.6.0
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filter Heartbeat AJAX response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array|object $response  The no-priv Heartbeat response object or array.
         * @param array        $data      An array of data passed via $_POST.
         * @param string       $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filter Heartbeat AJAX response when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The Heartbeat response object or array.
     * @param string       $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The no-priv Heartbeat response.
     * @param string       $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // Send the current time according to the server.
    $response['server_time'] = time();
    wp_send_json($response);
}

WordPress Version: 3.7

/**
 * WordPress Core Ajax Handlers.
 *
 * @package WordPress
 * @subpackage Administration
 */
/*
 * No-privilege Ajax handlers.
 */
/**
 * Heartbeat API (experimental)
 *
 * Runs when the user is not logged in.
 */
function wp_ajax_nopriv_heartbeat()
{
    $response = array();
    // screen_id is the same as $current_screen->id and the JS global 'pagenow'
    if (!empty($_POST['screen_id'])) {
        $screen_id = sanitize_key($_POST['screen_id']);
    } else {
        $screen_id = 'front';
    }
    if (!empty($_POST['data'])) {
        $data = wp_unslash((array) $_POST['data']);
        /**
         * Filter Heartbeat AJAX response in no-privilege environments.
         *
         * @since 3.6.0
         *
         * @param array|object $response  The no-priv Heartbeat response object or array.
         * @param array        $data      An array of data passed via $_POST.
         * @param string       $screen_id The screen id.
         */
        $response = apply_filters('heartbeat_nopriv_received', $response, $data, $screen_id);
    }
    /**
     * Filter Heartbeat AJAX response when no data is passed.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The Heartbeat response object or array.
     * @param string       $screen_id The screen id.
     */
    $response = apply_filters('heartbeat_nopriv_send', $response, $screen_id);
    /**
     * Fires when Heartbeat ticks in no-privilege environments.
     *
     * Allows the transport to be easily replaced with long-polling.
     *
     * @since 3.6.0
     *
     * @param array|object $response  The no-priv Heartbeat response.
     * @param string       $screen_id The screen id.
     */
    do_action('heartbeat_nopriv_tick', $response, $screen_id);
    // send the current time according to the server
    $response['server_time'] = time();
    wp_send_json($response);
}