The heartbeat_received ilter allows you to modify the Heartbeat response data in logged-in AJAX situations. It is the logged-in version of heartbeat_nopriv_received.
It was added in 3.6.
It is evaluated in wp_ajax_heartbeat() in the wp-admin/includes/ajax-actions.php file.
Like heartbeat_nopriv_received, heartbeat_received accepts 3 arguments:
- array|object
$responseThe nopriv Heartbeat response. - array
$dataAn array of data passed via$_POST. - string
$screen_idThe screen id.
Example:
Since we already have a working example for heartbeat_nopriv_received, we’ll reuse that here.
The following example is based on a Heartbeat example Gist written by Jason Coleman and kindly suggested by jsternberg in the comments.
It modifies the $response value to return a ‘marco polo’ scenario showing the server “responding” to the AJAX call. Thanks to for the suggestion!
View the code example on Gist.
Have a suggested improvement? You can fork the Gist and comment back with the link. If all is agreeable, I’ll merge in your changes. Crowd-sourced documentation FTW!