Skip to content

@alexkingorg /enqueue-heartbeat.php
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.