Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.0/11289.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/11289

* https://github.com/WordPress/gutenberg/pull/76643
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function create_item( $request ) {
* Load the real-time collaboration setting and, when enabled, ensure that an
* an autosave revision is always targeted.
*/
$is_collaboration_enabled = get_option( 'wp_enable_real_time_collaboration' );
$is_collaboration_enabled = get_option( 'wp_collaboration_enabled' );

if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
/*
Expand Down
21 changes: 16 additions & 5 deletions lib/compat/wordpress-7.0/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function gutenberg_rest_api_crdt_post_meta() {
* Registers the real-time collaboration setting.
*/
function gutenberg_register_real_time_collaboration_setting() {
$option_name = 'wp_enable_real_time_collaboration';
$option_name = 'wp_collaboration_enabled';

register_setting(
'writing',
Expand All @@ -124,8 +124,8 @@ function () use ( $option_name ) {
$option_value = get_option( $option_name );

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

if ( ! get_option( 'wp_collaboration_enabled' ) ) {
return;
}

// Temporary check to bridge the short time when this is change is merged in
// Gutenberg but not in core.
if ( ! get_option( 'wp_enable_real_time_collaboration' ) ) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the upgrade code runs in Gutenberg, this option won't be here anymore then. Is it still needed?

Copy link
Copy Markdown
Contributor Author

@chriszarate chriszarate Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed only for the brief window when this PR is open against / merged into Gutenberg and the equivalent change is not yet merged into Core trunk (since E2E tests run against Core trunk). After that, it can be removed.

return;
}
Expand All @@ -162,7 +168,12 @@ function gutenberg_inject_real_time_collaboration_setting() {
);
}
add_action( 'admin_init', 'gutenberg_inject_real_time_collaboration_setting' );
add_filter( 'default_option_wp_enable_real_time_collaboration', '__return_true' );

/**
* Core filters the default value, so hook with a higher priority to ensure the
* setting is enabled by default when the Gutenberg plugin is active.
*/
add_filter( 'default_option_wp_collaboration_enabled', '__return_true', 500 );
Comment on lines +172 to +176
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code will work. In the latest WordPress core, the initialization process persists the default value of wp_collaboration_enabled to 0 in the database. In this case, the default_option_{$option} filter should not be executed at all.

As a result, it appears that the e2e test is failing because RTC is not enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting that @alecgeatches and I are fixing those e2e tests for collaboration in #76704


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

if ( ! get_option( 'wp_enable_real_time_collaboration' ) ) {
if ( ! get_option( 'wp_collaboration_enabled' ) ) {
return;
}

Expand Down
28 changes: 26 additions & 2 deletions lib/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

/**
Expand All @@ -25,7 +25,7 @@ function _gutenberg_migrate_database() {
_gutenberg_migrate_remove_fse_drafts();
}

if ( version_compare( $gutenberg_installed_version, '22.6.0', '<' ) ) {
if ( version_compare( $gutenberg_installed_version, '22.8.0', '<' ) ) {
_gutenberg_migrate_enable_real_time_collaboration();
}

Expand Down Expand Up @@ -62,3 +62,27 @@ function _gutenberg_migrate_remove_fse_drafts() {
delete_option( 'gutenberg_last_synchronize_theme_template_checks' );
delete_option( 'gutenberg_last_synchronize_theme_template-part_checks' );
}

/**
* Update RTC option name.
*
* @since 22.8.0
*/
function _gutenberg_migrate_enable_real_time_collaboration() {
$value1 = get_option( 'enable_real_time_collaboration', '1' );
$value2 = get_option( 'wp_enable_real_time_collaboration', '1' );

// RTC is enabled by default in the plugin, so only set the value if it was
// previously disabled. Otherwise rely on the default value.
if ( ! $value1 || ! $value2 ) {
update_option( 'wp_collaboration_enabled', '0' );
}

delete_option( 'enable_real_time_collaboration' );
delete_option( 'wp_enable_real_time_collaboration' );
}

// Deletion of the `_wp_file_based` term (in _gutenberg_migrate_remove_fse_drafts) must happen
// after its taxonomy (`wp_theme`) is registered. This happens in `gutenberg_register_wp_theme_taxonomy`,
// which is hooked into `init` (default priority, i.e. 10).
add_action( 'init', '_gutenberg_migrate_database', 20 );
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export async function setCollaboration(
const html = await response.text();
const nonce = html.match( /name="_wpnonce" value="([^"]+)"/ )![ 1 ];

const optionName = 'wp_enable_real_time_collaboration';
const optionName = 'wp_collaboration_enabled';
const optionValue = enabled ? 1 : 0;

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

formData[ optionName ] = optionValue;

// Temporary addition to bridge the short time when this is change is merged in
// Gutenberg but not in core.
formData.wp_enable_real_time_collaboration = optionValue;

await requestUtils.request.post( '/wp-admin/options.php', {
form: formData,
failOnStatusCode: true,
Expand Down
Loading