Make WordPress Core


Ignore:
Timestamp:
02/19/2026 10:25:06 AM (3 months ago)
Author:
ellatrix
Message:

Real-time collaboration: add new REST endpoints, setting, and registered post meta.

Syncs/merges the PHP changes from the Gutenberg PR https://github.com/WordPress/gutenberg/pull/75366.

In Gutenberg, we have added support for real-time collaboration using CRDT documents (via the [Yjs library](https://yjs.dev/)). This work has suggested the following additions to WordPress:

  1. A default "sync provider" based on HTTP polling that allows collaborators to share updates with each other. Previously, we relied on WebRTC connections between collaborators for this purpose, but it proved unreliable under many network conditions.
    • Our solution is designed to work on any WordPress installation.
    • HTTP polling is the transport we identified as most likely to work universally.
    • Given the isolation and lifecycle of PHP processes, updates must be stored centrally in order to be shared among peers. We have chosen to store updates in post meta against a special post type, but alternate storage mechanisms are possible.
    • Collaborative editing can involve syncing multiple CRDT documents. To limit the number of connections consumed by this provider, requests are batched.
    • To prevent unbounded linear growth, updates are periodically compacted.
    • To avoid excessive load on lower-resourced hosts, this provider will benefit from usage limits (e.g., a maximum of three connected collaborators) enforced by the client (Gutenberg).
  1. A new registered post meta that allows Gutenberg to persist CRDT documents alongside posts.
    • This provides all collaborators with a "shared starting point" for the collaborative session, which avoids duplicate updates.
    • Content stored in the WordPress database always remains the source of truth. If the content differs from the persisted CRDT document, the CRDT document is updated to match the database.
  1. A new Writing setting that allows users to opt-in to real-time collaboration.
    • Enabling real-time collaboration disables post lock functionality and connects users to the sync provider.
  1. A behavior change to autosaves is needed. When the the original author is editing a draft post (post_status == 'draft' OR 'auto-draft') and they hold the post lock, the autosave targets the actual post instead of an autosave revision. This puts the post data and the persisted CRDT document out of sync and leads to duplicate updates. When real-time collaboration is enabled, all collaborators must autosave in the same way.

This PR provides a proposed implementation of the changes above. This corresponding Gutenberg PR moves the work from the experimental directory to lib/compat:

https://github.com/WordPress/gutenberg/pull/75366

Cumulative work to add this functionality can be found using this label:

https://github.com/WordPress/gutenberg/issues?q=label%3A%22%5BFeature%5D%20Real-time%20Collaboration%22%20is%3Apr

Developed https://github.com/WordPress/wordpress-develop/pull/10894.

Props czarate, paulkevan, ellatrix, timothyblynjacobs, westonruter, jorgefilipecosta, mindctrl.
Fixes #64622.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r61649 r61689  
    657657        )
    658658    );
     659
     660    if ( get_option( 'enable_real_time_collaboration' ) ) {
     661        register_post_type(
     662            'wp_sync_storage',
     663            array(
     664                'labels'             => array(
     665                    'name'          => __( 'Sync Updates' ),
     666                    'singular_name' => __( 'Sync Update' ),
     667                ),
     668                'public'             => false,
     669                '_builtin'           => true, /* internal use only. don't use this when registering your own post type. */
     670                'hierarchical'       => false,
     671                'capabilities'       => array(
     672                    'read'                   => 'do_not_allow',
     673                    'read_private_posts'     => 'do_not_allow',
     674                    'create_posts'           => 'do_not_allow',
     675                    'publish_posts'          => 'do_not_allow',
     676                    'edit_posts'             => 'do_not_allow',
     677                    'edit_others_posts'      => 'do_not_allow',
     678                    'edit_published_posts'   => 'do_not_allow',
     679                    'delete_posts'           => 'do_not_allow',
     680                    'delete_others_posts'    => 'do_not_allow',
     681                    'delete_published_posts' => 'do_not_allow',
     682                ),
     683                'map_meta_cap'       => false,
     684                'publicly_queryable' => false,
     685                'query_var'          => false,
     686                'rewrite'            => false,
     687                'show_in_menu'       => false,
     688                'show_in_rest'       => false,
     689                'show_ui'            => false,
     690                'supports'           => array( 'custom-fields' ),
     691            )
     692        );
     693    }
    659694
    660695    register_post_status(
     
    86128647 *
    86138648 * @since 6.3.0 Adds `wp_pattern_sync_status` meta field to the wp_block post type so an unsynced option can be added.
     8649 * @since 7.0.0 Adds `_crdt_document` meta field to post types so that CRDT documents can be persisted.
    86148650 *
    86158651 * @link https://github.com/WordPress/gutenberg/pull/51144
     
    86318667        )
    86328668    );
    8633 }
     8669
     8670    if ( get_option( 'enable_real_time_collaboration' ) ) {
     8671        register_meta(
     8672            'post',
     8673            '_crdt_document',
     8674            array(
     8675                'auth_callback'     => static function ( bool $_allowed, string $_meta_key, int $object_id, int $user_id ): bool {
     8676                    return user_can( $user_id, 'edit_post', $object_id );
     8677                },
     8678                /*
     8679                 * Revisions must be disabled because we always want to preserve
     8680                 * the latest persisted CRDT document, even when a revision is restored.
     8681                 * This ensures that we can continue to apply updates to a shared document
     8682                 * and peers can simply merge the restored revision like any other incoming
     8683                 * update.
     8684                 *
     8685                 * If we want to persist CRDT documents alongside revisions in the
     8686                 * future, we should do so in a separate meta key.
     8687                 */
     8688                'revisions_enabled' => false,
     8689                'show_in_rest'      => true,
     8690                'single'            => true,
     8691                'type'              => 'string',
     8692            )
     8693        );
     8694    }
     8695}
Note: See TracChangeset for help on using the changeset viewer.