Skip to content

Commit a53b58c

Browse files
chriszaratechriszaratesc0ttkclarkmaxschmelingingeniumed
authored andcommitted
RTC: Change RTC option name (#76643)
* Change RTC option name * Add backport changelog * Restore option migration * Cover previous option name in setCollaboration * Respect previous value in setting injection * Update migration const * Temporary bridge Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: sc0ttkclark <sc0ttkclark@git.wordpress.org> Co-authored-by: maxschmeling <maxschmeling@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org>
1 parent 4b4c756 commit a53b58c

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

backport-changelog/7.0/11289.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/11289
2+
3+
* https://github.com/WordPress/gutenberg/pull/76643

lib/compat/wordpress-7.0/class-gutenberg-rest-autosaves-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function create_item( $request ) {
101101
* Load the real-time collaboration setting and, when enabled, ensure that an
102102
* an autosave revision is always targeted.
103103
*/
104-
$is_collaboration_enabled = get_option( 'wp_enable_real_time_collaboration' );
104+
$is_collaboration_enabled = get_option( 'wp_collaboration_enabled' );
105105

106106
if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
107107
/*

lib/compat/wordpress-7.0/collaboration.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function gutenberg_rest_api_crdt_post_meta() {
103103
* Registers the real-time collaboration setting.
104104
*/
105105
function gutenberg_register_real_time_collaboration_setting() {
106-
$option_name = 'wp_enable_real_time_collaboration';
106+
$option_name = 'wp_collaboration_enabled';
107107

108108
register_setting(
109109
'writing',
@@ -124,8 +124,8 @@ function () use ( $option_name ) {
124124
$option_value = get_option( $option_name );
125125

126126
?>
127-
<label for="wp_enable_real_time_collaboration">
128-
<input name="wp_enable_real_time_collaboration" type="checkbox" id="wp_enable_real_time_collaboration" value="1" <?php checked( '1', $option_value ); ?>/>
127+
<label for="wp_collaboration_enabled">
128+
<input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', $option_value ); ?>/>
129129
<?php _e( 'Enable real-time collaboration', 'gutenberg' ); ?>
130130
</label>
131131
<?php
@@ -142,6 +142,12 @@ function () use ( $option_name ) {
142142
function gutenberg_inject_real_time_collaboration_setting() {
143143
global $pagenow;
144144

145+
if ( ! get_option( 'wp_collaboration_enabled' ) ) {
146+
return;
147+
}
148+
149+
// Temporary check to bridge the short time when this is change is merged in
150+
// Gutenberg but not in core.
145151
if ( ! get_option( 'wp_enable_real_time_collaboration' ) ) {
146152
return;
147153
}
@@ -162,7 +168,12 @@ function gutenberg_inject_real_time_collaboration_setting() {
162168
);
163169
}
164170
add_action( 'admin_init', 'gutenberg_inject_real_time_collaboration_setting' );
165-
add_filter( 'default_option_wp_enable_real_time_collaboration', '__return_true' );
171+
172+
/**
173+
* Core filters the default value, so hook with a higher priority to ensure the
174+
* setting is enabled by default when the Gutenberg plugin is active.
175+
*/
176+
add_filter( 'default_option_wp_collaboration_enabled', '__return_true', 500 );
166177

167178
/**
168179
* Modifies the post list UI and heartbeat responses for real-time collaboration.
@@ -175,7 +186,7 @@ function gutenberg_inject_real_time_collaboration_setting() {
175186
function gutenberg_post_list_collaboration_ui() {
176187
global $pagenow;
177188

178-
if ( ! get_option( 'wp_enable_real_time_collaboration' ) ) {
189+
if ( ! get_option( 'wp_collaboration_enabled' ) ) {
179190
return;
180191
}
181192

lib/upgrade.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
if ( ! defined( '_GUTENBERG_VERSION_MIGRATION' ) ) {
99
// It's necessary to update this version every time a new migration is needed.
10-
define( '_GUTENBERG_VERSION_MIGRATION', '22.6.0' );
10+
define( '_GUTENBERG_VERSION_MIGRATION', '22.8.0' );
1111
}
1212

1313
/**
@@ -25,7 +25,7 @@ function _gutenberg_migrate_database() {
2525
_gutenberg_migrate_remove_fse_drafts();
2626
}
2727

28-
if ( version_compare( $gutenberg_installed_version, '22.6.0', '<' ) ) {
28+
if ( version_compare( $gutenberg_installed_version, '22.8.0', '<' ) ) {
2929
_gutenberg_migrate_enable_real_time_collaboration();
3030
}
3131

@@ -62,3 +62,27 @@ function _gutenberg_migrate_remove_fse_drafts() {
6262
delete_option( 'gutenberg_last_synchronize_theme_template_checks' );
6363
delete_option( 'gutenberg_last_synchronize_theme_template-part_checks' );
6464
}
65+
66+
/**
67+
* Update RTC option name.
68+
*
69+
* @since 22.8.0
70+
*/
71+
function _gutenberg_migrate_enable_real_time_collaboration() {
72+
$value1 = get_option( 'enable_real_time_collaboration', '1' );
73+
$value2 = get_option( 'wp_enable_real_time_collaboration', '1' );
74+
75+
// RTC is enabled by default in the plugin, so only set the value if it was
76+
// previously disabled. Otherwise rely on the default value.
77+
if ( ! $value1 || ! $value2 ) {
78+
update_option( 'wp_collaboration_enabled', '0' );
79+
}
80+
81+
delete_option( 'enable_real_time_collaboration' );
82+
delete_option( 'wp_enable_real_time_collaboration' );
83+
}
84+
85+
// Deletion of the `_wp_file_based` term (in _gutenberg_migrate_remove_fse_drafts) must happen
86+
// after its taxonomy (`wp_theme`) is registered. This happens in `gutenberg_register_wp_theme_taxonomy`,
87+
// which is hooked into `init` (default priority, i.e. 10).
88+
add_action( 'init', '_gutenberg_migrate_database', 20 );

test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export async function setCollaboration(
334334
const html = await response.text();
335335
const nonce = html.match( /name="_wpnonce" value="([^"]+)"/ )![ 1 ];
336336

337-
const optionName = 'wp_enable_real_time_collaboration';
337+
const optionName = 'wp_collaboration_enabled';
338338
const optionValue = enabled ? 1 : 0;
339339

340340
const formData: Record< string, string | number > = {
@@ -349,6 +349,10 @@ export async function setCollaboration(
349349

350350
formData[ optionName ] = optionValue;
351351

352+
// Temporary addition to bridge the short time when this is change is merged in
353+
// Gutenberg but not in core.
354+
formData.wp_enable_real_time_collaboration = optionValue;
355+
352356
await requestUtils.request.post( '/wp-admin/options.php', {
353357
form: formData,
354358
failOnStatusCode: true,

0 commit comments

Comments
 (0)