The heartbeat_nopriv_received
filter allows you to modify the Heartbeat response data in no-privilege — that is, non-logged-in AJAX situations such as for use on the front-end.
It was added in 3.6.
It is evaluated in wp_ajax_nopriv_heartbeat()
in the wp-admin/includes/ajax-actions.php file.
heartbeat_nopriv_received
accepts 3 arguments:
- array|object
$response
The nopriv Heartbeat response. - array
$data
An array of data passed via$_POST
. - string
$screen_id
The screen id.
Example:
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!
Although a bit out of date (pre-3.6 release), this snippet by Jason Coleman is a good example for using this filter: https://gist.github.com/strangerstudios/5888123
Excellent. I’ve adapted and updated Jason’s example and added it to the post. Thanks for the suggestion!