Skip to content

Commit d1d3040

Browse files
committed
Guard registration of post type and REST endpoints if option is not enabled
1 parent 4652456 commit d1d3040

2 files changed

Lines changed: 64 additions & 58 deletions

File tree

src/wp-includes/post.php

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -657,38 +657,40 @@ function create_initial_post_types() {
657657
)
658658
);
659659

660-
register_post_type(
661-
'wp_sync_storage',
662-
array(
663-
'labels' => array(
664-
'name' => __( 'Sync Updates' ),
665-
'singular_name' => __( 'Sync Update' ),
666-
),
667-
'public' => false,
668-
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
669-
'hierarchical' => false,
670-
'capabilities' => array(
671-
'read' => 'do_not_allow',
672-
'read_private_posts' => 'do_not_allow',
673-
'create_posts' => 'do_not_allow',
674-
'publish_posts' => 'do_not_allow',
675-
'edit_posts' => 'do_not_allow',
676-
'edit_others_posts' => 'do_not_allow',
677-
'edit_published_posts' => 'do_not_allow',
678-
'delete_posts' => 'do_not_allow',
679-
'delete_others_posts' => 'do_not_allow',
680-
'delete_published_posts' => 'do_not_allow',
681-
),
682-
'map_meta_cap' => false,
683-
'publicly_queryable' => false,
684-
'query_var' => false,
685-
'rewrite' => false,
686-
'show_in_menu' => false,
687-
'show_in_rest' => false,
688-
'show_ui' => false,
689-
'supports' => array( 'custom-fields' ),
690-
)
691-
);
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+
}
692694

693695
register_post_status(
694696
'publish',
@@ -8665,27 +8667,29 @@ function wp_create_initial_post_meta() {
86658667
)
86668668
);
86678669

8668-
register_meta(
8669-
'post',
8670-
'_crdt_document',
8671-
array(
8672-
'auth_callback' => static function ( bool $_allowed, string $_meta_key, int $object_id, int $user_id ): bool {
8673-
return user_can( $user_id, 'edit_post', $object_id );
8674-
},
8675-
/*
8676-
* Revisions must be disabled because we always want to preserve
8677-
* the latest persisted CRDT document, even when a revision is restored.
8678-
* This ensures that we can continue to apply updates to a shared document
8679-
* and peers can simply merge the restored revision like any other incoming
8680-
* update.
8681-
*
8682-
* If we want to persist CRDT documents alongside revisions in the
8683-
* future, we should do so in a separate meta key.
8684-
*/
8685-
'revisions_enabled' => false,
8686-
'show_in_rest' => true,
8687-
'single' => true,
8688-
'type' => 'string',
8689-
)
8690-
);
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+
}
86918695
}

src/wp-includes/rest-api.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,11 @@ function create_initial_rest_routes() {
430430
$icons_controller->register_routes();
431431

432432
// Collaboration.
433-
$sync_storage = new WP_Sync_Post_Meta_Storage();
434-
$sync_server = new WP_HTTP_Polling_Sync_Server( $sync_storage );
435-
$sync_server->register_routes();
433+
if ( get_option( 'enable_real_time_collaboration' ) ) {
434+
$sync_storage = new WP_Sync_Post_Meta_Storage();
435+
$sync_server = new WP_HTTP_Polling_Sync_Server( $sync_storage );
436+
$sync_server->register_routes();
437+
}
436438
}
437439

438440
/**

0 commit comments

Comments
 (0)