Skip to content

Commit 1f333db

Browse files
committed
Real-time collaboration: Rename option for positive intent.
This reverts the real time collaboration option name back to `wp_enable_real_time_collaboration` to avoid the need to turn on a checkbox in order to turn off the feature. This is to reduce the cognitive load on both users and developers of an on is off paradigm. To ensure Real Time Collaboration is enabled prior to the upgrade routine running on multi-site installs, the option default is filtered on the `default_option_wp_enable_real_time_collaboration` hook to enable the option by default. Developed in: #11161 Follow up to r61828. Props peterwilsoncc, czarate, sergeybiryukov. Fixes #64622. git-svn-id: https://develop.svn.wordpress.org/trunk@61833 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e1c433c commit 1f333db

13 files changed

Lines changed: 29 additions & 31 deletions

File tree

src/wp-admin/includes/schema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ function populate_options( array $options = array() ) {
563563

564564
// 6.9.0
565565
'wp_notes_notify' => 1,
566+
567+
// 7.0.0
568+
'wp_enable_real_time_collaboration' => 1,
566569
);
567570

568571
// 3.3.0

src/wp-admin/options-writing.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@
110110
</td>
111111
</tr>
112112
<tr>
113-
<th scope="row"><label for="wp_disable_real_time_collaboration"><?php _e( 'Collaboration' ); ?></label></th>
113+
<th scope="row"><label for="wp_enable_real_time_collaboration"><?php _e( 'Collaboration' ); ?></label></th>
114114
<td>
115-
<input name="wp_disable_real_time_collaboration" type="checkbox" id="wp_disable_real_time_collaboration" value="1" <?php checked( '1', get_option( 'wp_disable_real_time_collaboration' ) ); ?> />
116-
<label for="wp_disable_real_time_collaboration"><?php _e( 'Disable real-time collaboration' ); ?></label>
115+
<input name="wp_enable_real_time_collaboration" type="checkbox" id="wp_enable_real_time_collaboration" value="1" <?php checked( '1', get_option( 'wp_enable_real_time_collaboration' ) ); ?> />
116+
<label for="wp_enable_real_time_collaboration"><?php _e( 'Enable real-time collaboration' ); ?></label>
117117
</td>
118118
</tr>
119119
<?php

src/wp-admin/options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
'default_email_category',
154154
'default_link_category',
155155
'default_post_format',
156-
'wp_disable_real_time_collaboration',
156+
'wp_enable_real_time_collaboration',
157157
),
158158
);
159159
$allowed_options['misc'] = array();

src/wp-includes/collaboration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @access private
1515
*/
1616
function wp_collaboration_inject_setting() {
17-
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
17+
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
1818
wp_add_inline_script(
1919
'wp-core-data',
2020
'window._wpCollaborationEnabled = true;',

src/wp-includes/default-filters.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,9 @@
485485
// Timezone.
486486
add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_offset' );
487487

488-
// If the upgrade hasn't run yet, assume link manager is used.
489-
add_filter( 'default_option_link_manager_enabled', '__return_true' );
488+
// If the upgrade hasn't run yet, set some default options.
489+
add_filter( 'default_option_link_manager_enabled', '__return_true' ); // Assume link manager is used.
490+
add_filter( 'default_option_wp_enable_real_time_collaboration', '__return_true' ); // Enable real-time collaboration.
490491

491492
// This option no longer exists; tell plugins we always support auto-embedding.
492493
add_filter( 'pre_option_embed_autourls', '__return_true' );

src/wp-includes/option.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,10 +2887,10 @@ function register_initial_settings() {
28872887

28882888
register_setting(
28892889
'writing',
2890-
'wp_disable_real_time_collaboration',
2890+
'wp_enable_real_time_collaboration',
28912891
array(
28922892
'type' => 'boolean',
2893-
'description' => __( 'Disable real-time collaboration' ),
2893+
'description' => __( 'Enable Real-Time Collaboration' ),
28942894
'sanitize_callback' => 'rest_sanitize_boolean',
28952895
'default' => false,
28962896
'show_in_rest' => true,

src/wp-includes/post.php

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

660-
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
660+
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
661661
register_post_type(
662662
'wp_sync_storage',
663663
array(
@@ -8671,7 +8671,7 @@ function wp_create_initial_post_meta() {
86718671
)
86728672
);
86738673

8674-
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
8674+
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
86758675
register_meta(
86768676
'post',
86778677
'_crdt_document',

src/wp-includes/rest-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function create_initial_rest_routes() {
430430
$icons_controller->register_routes();
431431

432432
// Collaboration.
433-
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
433+
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
434434
$sync_storage = new WP_Sync_Post_Meta_Storage();
435435
$sync_server = new WP_HTTP_Polling_Sync_Server( $sync_storage );
436436
$sync_server->register_routes();

src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ public function create_item( $request ) {
254254
* the saved post. This diff is then applied to the in-memory CRDT
255255
* document, which can lead to duplicate inserts or deletions.
256256
*/
257-
$is_collaboration_disabled = boolval( get_option( 'wp_disable_real_time_collaboration' ) );
257+
$is_collaboration_enabled = get_option( 'wp_enable_real_time_collaboration' );
258258

259-
if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && $is_collaboration_disabled ) {
259+
if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
260260
/*
261261
* Draft posts for the same author: autosaving updates the post and does not create a revision.
262262
* Convert the post object to an array and add slashes, wp_update_post() expects escaped array.

tests/phpunit/tests/rest-api/rest-autosaves-controller.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public function test_rest_autosave_published_post() {
570570
}
571571

572572
public function test_rest_autosave_draft_post_same_author() {
573-
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
573+
add_filter( 'pre_option_wp_enable_real_time_collaboration', '__return_zero' ); // Zero as false doesn't work for pre-flight options.
574574

575575
wp_set_current_user( self::$editor_id );
576576

@@ -606,7 +606,6 @@ public function test_rest_autosave_draft_post_same_author() {
606606
$this->assertSame( $post_data['post_excerpt'], $post->post_excerpt );
607607

608608
wp_delete_post( $post_id );
609-
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
610609
}
611610

612611
public function test_rest_autosave_draft_post_different_author() {
@@ -747,7 +746,7 @@ public function test_get_item_sets_up_postdata() {
747746
}
748747

749748
public function test_update_item_draft_page_with_parent() {
750-
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
749+
add_filter( 'pre_option_wp_enable_real_time_collaboration', '__return_zero' ); // Zero as false doesn't work for pre-flight options.
751750

752751
wp_set_current_user( self::$editor_id );
753752
$request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$child_draft_page_id . '/autosaves' );
@@ -766,8 +765,6 @@ public function test_update_item_draft_page_with_parent() {
766765

767766
$this->assertSame( self::$child_draft_page_id, $data['id'] );
768767
$this->assertSame( self::$parent_page_id, $data['parent'] );
769-
770-
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
771768
}
772769

773770
public function test_schema_validation_is_applied() {
@@ -933,7 +930,7 @@ public static function data_head_request_with_specified_fields_returns_success_r
933930
* same author should create a revision instead of updating the post directly.
934931
*/
935932
public function test_rest_autosave_draft_post_same_author_with_rtc() {
936-
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
933+
add_filter( 'pre_option_wp_enable_real_time_collaboration', '__return_true' );
937934

938935
wp_set_current_user( self::$editor_id );
939936

@@ -972,15 +969,14 @@ public function test_rest_autosave_draft_post_same_author_with_rtc() {
972969
$this->assertSame( $post_data['post_excerpt'], $post->post_excerpt );
973970

974971
wp_delete_post( $post_id );
975-
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
976972
}
977973

978974
/**
979975
* When real-time collaboration is enabled, autosaving a draft page with
980976
* a parent should create a revision instead of updating the page directly.
981977
*/
982978
public function test_update_item_draft_page_with_parent_with_rtc() {
983-
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
979+
add_filter( 'pre_option_wp_enable_real_time_collaboration', '__return_true' );
984980

985981
wp_set_current_user( self::$editor_id );
986982
$request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$child_draft_page_id . '/autosaves' );
@@ -1000,7 +996,5 @@ public function test_update_item_draft_page_with_parent_with_rtc() {
1000996
// With RTC enabled, a revision is created instead of updating the page.
1001997
$this->assertNotSame( self::$child_draft_page_id, $data['id'] );
1002998
$this->assertSame( self::$child_draft_page_id, $data['parent'] );
1003-
1004-
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
1005999
}
10061000
}

0 commit comments

Comments
 (0)