You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress文章锁定机制:如何判定用户停止编辑及推断状态?

How WordPress Detects When a User Stops Editing a Post

Great question—you’ve already nailed the two core pieces of the puzzle with the AJAX heartbeats and wp_postmeta storage. Let me connect the dots on how the system actually infers when a user has stopped editing:

  • The heartbeat request’s role in extending the lock
    Every ~15 seconds, the WordPress editor sends an AJAX request to wp-admin/admin-ajax.php with the heartbeat action. This request doesn’t just "refresh" the lock—it actively updates the _edit_lock meta value in the wp_postmeta table. The value stored is a string formatted like {user_id}:{expiration_timestamp}, where the expiration timestamp is set to the current server time plus 15 seconds (the interval of the next expected heartbeat).

  • Detecting inactivity via expired timestamps
    WordPress doesn’t need to "watch" for a user to explicitly stop editing. Instead, it uses a passive expiration check:

    • If the user keeps editing (and the heartbeats keep firing), the _edit_lock timestamp gets updated every 15 seconds, pushing the expiration further out.
    • When the user stops editing—whether they close the tab, navigate away, lose internet, or just step away—the heartbeat requests stop. The _edit_lock timestamp stops being updated, and eventually, the current server time will pass that expiration value.
  • Checking lock status for other users
    When another admin tries to edit the same post, WordPress checks the _edit_lock meta value:

    • If the expiration timestamp is still in the future, it shows the post as locked by the original user.
    • If the timestamp is in the past, it treats the lock as expired, allowing the new user to take over editing (and start their own heartbeat cycle to update the lock).

And you’re right—this system doesn’t use WebSockets at all. The periodic AJAX heartbeats are lightweight enough for this low-frequency state sync, and the expiration-based check keeps the logic simple and reliable.

内容的提问来源于stack exchange,提问作者i.brod

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 07:02:25