I set out to create a post locking system so that user B can't edit post X when user A is editing it. I read that Wordpress has a similar feature. I've combed over the code however I can't quite figure out one thing. How do they handle removing the post lock when the user exits the browser or directly navigates away from the page?
Wordpress seems to use something they call the “Heartbeat API” which is just a simple server poller that communicates with admin-ajax.php and handles things such as adding/removing post locks.
So there a few scenarios that I’ve observed:
- User stays on page (admin-ajax.php triggered after preset interval, post lock renewed)
User navigates away from page to another wordpress page (admin-ajax.php triggered, post lock removed)
3. User navigates to another website directly from the current website page (admin-ajax.php not triggered; however post lock is removed)
Broadly, how do they achieve the 3rd?
I ruled out a timeout or inability to connect to admin-ajax.php just because when I (as the currently editing user) stay on the page but turn requests to offline in dev tools the post lock still stays on (as it appears to other users) despite failed requests to admin-ajax.php.