Create a gist now

Instantly share code, notes, and snippets.

WordPress 3.5 Compatible Heartbeat API Usage
<?php
// enqueue the script,
// this fails gracefully if no 'heartbeat' script is registered
wp_enqueue_script('heartbeat');
(function($) {
// watch for heartbeat event,
// no event will happen if the script isn't included
$(document).on('heartbeat-connection-lost', function() {
// do what you need to do here
$('body').addClass('connection-lost')
}).on('heartbeat-connection-restored', function() {
// do what you need to do here
$('body').removeClass('connection-lost')
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment