Contents

Real-time collaboration

When several people edit one post at the same time, the editor shows each person's cursor. If the plugin behind that keeps those cursors in Presence API's table, the same people also appear in the admin bar and the post lists.

How it works #

Awareness rows shared with presenceThe block editor sends awareness, such as cursors and selections, and edits to a collaboration plugin. The plugin writes awareness as rows with its own prefix in the post room in wp_presence, where admin screens also read them. It keeps edits in its own storage.awareness, as gse- rowsedits

Block editor

Collaboration plugin

wp_presence
postType/post:42

Plugin's own storage

Admin bar, Active Posts,
Editors column

Collaboration signals #

This plugin counts a post room's editors by its own editor- rows. Rows under any other prefix, and agent rows, are not counted.

Signal Fires when
wp_presence_collaboration_started A post room goes from one editor to two or more
wp_presence_collaboration_ended It goes back to one
presence-api.collaborationStarted, presence-api.collaborationEnded The same edges, in the editor's browser
presence-api.watchingRoom The editor's script loads in a post room

The last count is kept in the reserved _collab row, so the edges hold across requests. A collaboration plugin can wait for presence-api.collaborationStarted instead of polling to learn whether anyone else is editing.

Reading a room in the editor #

wp.presence.usePresenceUsers( room ), in the wp-presence script, returns the other people in a room. It reads the room over the REST API on each Heartbeat tick, from one tab.

Source: heartbeat.php · use-presence-users.js · Relationship to the block editor

Check your understanding #

A collaboration plugin writes gse- rows in a post room. Do they count toward wp_presence_collaboration_started?

No. The count uses this plugin's editor- rows only.

Edit this page on GitHub