PluginProbe
Gutenberg / 22.4.4
Gutenberg v22.4.4
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experimental / synchronization.php

synchronization.php in Gutenberg 22.4.4, at lib/experimental/synchronization.php

38 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstraps synchronization (collaborative editing).
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers post meta for persisting CRDT documents.
10 */
11 function gutenberg_rest_api_crdt_post_meta() {
12 // This string must match WORDPRESS_META_KEY_FOR_CRDT_DOC_PERSISTENCE in @wordpress/sync.
13 $persisted_crdt_post_meta_key = '_crdt_document';
14
15 register_meta(
16 'post',
17 $persisted_crdt_post_meta_key,
18 array(
19 'auth_callback' => function ( bool $_allowed, string $_meta_key, int $object_id, int $user_id ): bool {
20 return user_can( $user_id, 'edit_post', $object_id );
21 },
22 // IMPORTANT: Revisions must be disabled because we always want to preserve
23 // the latest persisted CRDT document, even when a revision is restored.
24 // This ensures that we can continue to apply updates to a shared document
25 // and peers can simply merge the restored revision like any other incoming
26 // update.
27 //
28 // If we want to persist CRDT documents alongisde revisions in the
29 // future, we should do so in a separate meta key.
30 'revisions_enabled' => false,
31 'show_in_rest' => true,
32 'single' => true,
33 'type' => 'string',
34 )
35 );
36 }
37 add_action( 'init', 'gutenberg_rest_api_crdt_post_meta' );
38