Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
Last active December 16, 2015 04:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkingorg/5381074 to your computer and use it in GitHub Desktop.
Save alexkingorg/5381074 to your computer and use it in GitHub Desktop.
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