WordPress 3.6 is Alive: The New Heartbeat API

We’ve been anticipating the release of WordPress 3.6 for weeks now, but it’s definitely alive – and you could say it even has a pulse.

The Heartbeat API will be a new feature introduced in the latest release. It’s been designed to deliver login expiration notifications, provide post locking and trigger autosaves – making writers like me very happy.

According to Andrew Ozz who is leading the API’s development:

Frustrated with WordPress
There is nothing worse than losing a lengthy post. Hopefully the new Heartbeat API will put a stop to writers’ frustrations.

“The purpose of this API is to simulate bidirectional connection between the browser and the server. Initially it will be used for autosave, post locking and log-in expiration warning while a user is writing or editing.

The idea is to have a relatively simple API that sends XHR requests to the server every 15 seconds and triggers events (or callbacks) on receiving data. Other components would be able to “hitch a ride” or get notified about another user’s activities.

In the future this can be used to block simultaneous editing of widgets and menus or any other tasks that require regular updates from the server.”

The “heartbeat” will be set to a default 15 second interval when the browser window is in focus and the user is active. When the window is out of focus or there aren’t any mouse and keyboard strokes for 5 minutes, that interval drops to 2 minutes.

Locking posts has been a sought after feature, giving people who work on websites with multiple authors editing posts, like WPMU.org, the ability to “lock” posts. The last Autosave update at Make WordPress Core reveals a dialog box will be shown either when an author visits a locked post or when a post becomes locked. When you visit an already locked post you will have the option to break the lock and take over control of a post, a handy feature if you’re an editor.

WordPress locking posts
WordPress 3.6 will feature post locking to stop others meddling with your work.

As I mentioned above, autosaving is important to writers. There’s nothing worse than tapping out a long and carefully written post and then losing every single freaking word when there’s a brownout or your cat has jumped onto your mouse and inadvertently navigated to another browser page. I’ve sworn at my laptop, at WordPress, and for a while started writing posts in Notepad to avoid using the WordPress post editor.

So I was a very happy camper when Mark Jacquith acknowledged my pain and the pain of others before me back in January when he announced an update to the autosave feature in 3.6, enabling autosaving to the browser’s local storage:

I want, as a major 3.6 bullet point, that we should never lose posts due to expired cookies, loss of connection, inadvertent navigation (even if AYS’d), plugin or core errors on save, browser crashes, OS crashes, cats walking on keyboards, children drooling in keyboards, etc. I want people to trust WordPress with their posts.

They should never fear that something they’ve spent time creating or editing should go away due to their mistake or ours or that of a third party. Mistakes and errors should be recoverable. I can’t stress enough how important it is that people believe this and have good reason to believe it. If a post gets lost, there is a catastrophic loss of trust, that could take years to be regained (if indeed it ever is). This is people’s time and their creative output we’re talking about. If we’re not valuing those things above all else, then our priorities are seriously out of order.

This is an all-hands-on-deck item for 3.6. Even if you’re not actively working on the code or the copy or the UI or the UX I want you to be thinking about ways in which WordPress could better treat your creative output as the valuable artifact it is.

The last Autosave update also reveals improved user logout notification is now in core and its UI has been tweaked to directly show the login box, rather than prompting first. According to Ozz, there was discussion as to whether it was better not to block a user’s access to the editor/current page when it was detected they not longer had a login token, since it would stop the user while they were in the middle of a sentence.

Hopefully we’ll see another Autosave update soon as there hasn’t been one in a while.

There will be a lot of opportunities for developers and plugin and theme sellers to make the most of the heartbeat. Mike Hansen has suggested it could be used to enable comments on posts to auto populate while someone is viewing them, blog posts could auto populate while a reader is viewing all posts and forums such as bbPress could even become interactive like a chat room. Pretty cool stuff.

heartbeat test plugin is available if you want to try it out.

What else do you think the heartbeat could be used for? Tell us in the comments below.

Credits: hyekab25, Aaron JacobsDavidDennisPhotos.com