WordPress Heartbeat API: An Introduction

WordPress

If I were to mention to a casual WordPress user something about the WordPress Heartbeat API, most would have never even heard of it, much less know that it’s been in WordPress since version 3.6(!) with very little fanfare.  But, as it turns out, the Heartbeat API has gained traction in the developer community, as people are starting to utilize it to create some amazing plugins and use cases for WordPress.  With this newfound popularity, I thought it would be great for us to dive into the WordPress Heartbeat API and see exactly what makes it… tick (see what I did there?)

What is the WordPress Heartbeat API

Heartbeat (not to be confused with Heartbleed) can be described, at its easiest, as the pulse of your blog.  Like a literal heart, your blog has a steady rhythm that it keeps running in the background as users are surfing the site.  At certain point, and if certain conditions are met, you can trigger actions onto the Heartbeat.  It’s a continuous conversation between a user’s browser and the server.  Unlike a lot of these technologies, the WordPress Heartbeat API can be accessed both by PHP _and_ by Javascript (and, conversely, Ajax!).  This brings a whole slew of options that we can hook into and do some really cool things.

Plugins Utilizing the WordPress Heartbeat API

Here’s a list of the ones I’ve found that work well on the front-end that utilize the WordPress Heartbeat API:

…and that’s it.  Really.  There are quite a few that use Heartbeat on the back-end, but these are the ones that utilize it for “forward facing” items such as store stock and notifications.

To be honest, I feel like there’s a huge gap when it comes to the Heartbeat API that goes beyond lack of utilization – there seems to be a lack of understanding as to what it does.  Documentation exists, as do a few tutorials, but there’s an opportunity for someone savvy in WordPress, Javascript, and AJAX to come in and completely dominate using this technology.

Of real interest is the WP Heartbeat Notify, which is designed as a template for other plugins.

So, if you’re a developer and want to tinker with one of WordPress’ most underutilized features, I would look into the Heartbeat API.  There’s tons of potential there, but with such little integration there’s a golden opportunity for someone with the right idea to come along and crush it.