Skip to content
Closed
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: 0 additions & 3 deletions src/wp-admin/includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,6 @@ function populate_options( array $options = array() ) {

// 6.9.0
'wp_notes_notify' => 1,

// 7.0.0
'wp_enable_real_time_collaboration' => 0,
);

// 3.3.0
Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/options-writing.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
</td>
</tr>
<tr>
<th scope="row"><label for="wp_enable_real_time_collaboration"><?php _e( 'Collaboration' ); ?></label></th>
<th scope="row"><label for="wp_disable_real_time_collaboration"><?php _e( 'Collaboration' ); ?></label></th>
<td>
<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' ) ); ?> />
<label for="wp_enable_real_time_collaboration"><?php _e( 'Enable real-time collaboration' ); ?></label>
<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' ) ); ?> />
<label for="wp_disable_real_time_collaboration"><?php _e( 'Disable real-time collaboration' ); ?></label>
</td>
</tr>
<?php
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
'default_email_category',
'default_link_category',
'default_post_format',
'wp_enable_real_time_collaboration',
'wp_disable_real_time_collaboration',
),
);
$allowed_options['misc'] = array();
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @access private
*/
function wp_collaboration_inject_setting() {
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
wp_add_inline_script(
'wp-core-data',
'window._wpCollaborationEnabled = true;',
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -2887,10 +2887,10 @@ function register_initial_settings() {

register_setting(
'writing',
'wp_enable_real_time_collaboration',
'wp_disable_real_time_collaboration',
array(
'type' => 'boolean',
'description' => __( 'Enable Real-Time Collaboration' ),
'description' => __( 'Disable real-time collaboration' ),
'sanitize_callback' => 'rest_sanitize_boolean',
'default' => false,
'show_in_rest' => true,
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ function create_initial_post_types() {
)
);

if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
register_post_type(
'wp_sync_storage',
array(
Expand Down Expand Up @@ -8671,7 +8671,7 @@ function wp_create_initial_post_meta() {
)
);

if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
register_meta(
'post',
'_crdt_document',
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function create_initial_rest_routes() {
$icons_controller->register_routes();

// Collaboration.
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
if ( ! boolval( get_option( 'wp_disable_real_time_collaboration' ) ) ) {
$sync_storage = new WP_Sync_Post_Meta_Storage();
$sync_server = new WP_HTTP_Polling_Sync_Server( $sync_storage );
$sync_server->register_routes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public function create_item( $request ) {
* the saved post. This diff is then applied to the in-memory CRDT
* document, which can lead to duplicate inserts or deletions.
*/
$is_collaboration_enabled = get_option( 'wp_enable_real_time_collaboration' );
$is_collaboration_disabled = boolval( get_option( 'wp_disable_real_time_collaboration' ) );

if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && $is_collaboration_disabled ) {
/*
* Draft posts for the same author: autosaving updates the post and does not create a revision.
* Convert the post object to an array and add slashes, wp_update_post() expects escaped array.
Expand Down
22 changes: 10 additions & 12 deletions tests/phpunit/tests/rest-api/rest-autosaves-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,7 @@ public function test_rest_autosave_published_post() {
}

public function test_rest_autosave_draft_post_same_author() {
$original_option = get_option( 'wp_enable_real_time_collaboration' );
update_option( 'wp_enable_real_time_collaboration', false );
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );

wp_set_current_user( self::$editor_id );

Expand Down Expand Up @@ -607,7 +606,7 @@ public function test_rest_autosave_draft_post_same_author() {
$this->assertSame( $post_data['post_excerpt'], $post->post_excerpt );

wp_delete_post( $post_id );
update_option( 'wp_enable_real_time_collaboration', $original_option );
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
}

public function test_rest_autosave_draft_post_different_author() {
Expand Down Expand Up @@ -748,8 +747,7 @@ public function test_get_item_sets_up_postdata() {
}

public function test_update_item_draft_page_with_parent() {
$original_option = get_option( 'wp_enable_real_time_collaboration' );
update_option( 'wp_enable_real_time_collaboration', false );
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );

wp_set_current_user( self::$editor_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$child_draft_page_id . '/autosaves' );
Expand All @@ -768,7 +766,8 @@ public function test_update_item_draft_page_with_parent() {

$this->assertSame( self::$child_draft_page_id, $data['id'] );
$this->assertSame( self::$parent_page_id, $data['parent'] );
update_option( 'wp_enable_real_time_collaboration', $original_option );

remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_true' );
}

public function test_schema_validation_is_applied() {
Expand Down Expand Up @@ -934,8 +933,7 @@ public static function data_head_request_with_specified_fields_returns_success_r
* same author should create a revision instead of updating the post directly.
*/
public function test_rest_autosave_draft_post_same_author_with_rtc() {
$original_option = get_option( 'wp_enable_real_time_collaboration' );
update_option( 'wp_enable_real_time_collaboration', true );
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );

wp_set_current_user( self::$editor_id );

Expand Down Expand Up @@ -974,16 +972,15 @@ public function test_rest_autosave_draft_post_same_author_with_rtc() {
$this->assertSame( $post_data['post_excerpt'], $post->post_excerpt );

wp_delete_post( $post_id );
update_option( 'wp_enable_real_time_collaboration', $original_option );
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
}

/**
* When real-time collaboration is enabled, autosaving a draft page with
* a parent should create a revision instead of updating the page directly.
*/
public function test_update_item_draft_page_with_parent_with_rtc() {
$original_option = get_option( 'wp_enable_real_time_collaboration' );
update_option( 'wp_enable_real_time_collaboration', true );
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );

wp_set_current_user( self::$editor_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$child_draft_page_id . '/autosaves' );
Expand All @@ -1003,6 +1000,7 @@ public function test_update_item_draft_page_with_parent_with_rtc() {
// With RTC enabled, a revision is created instead of updating the page.
$this->assertNotSame( self::$child_draft_page_id, $data['id'] );
$this->assertSame( self::$child_draft_page_id, $data['parent'] );
update_option( 'wp_enable_real_time_collaboration', $original_option );

remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/tests/rest-api/rest-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function test_get_items() {
'default_ping_status',
'default_comment_status',
'site_icon', // Registered in wp-includes/blocks/site-logo.php
'wp_enable_real_time_collaboration',
'wp_disable_real_time_collaboration',
// Connectors API keys are registered in _wp_register_default_connector_settings() in wp-includes/connectors.php.
'connectors_ai_anthropic_api_key',
'connectors_ai_google_api_key',
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/rest-api/rest-sync-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WP_Test_REST_Sync_Server extends WP_Test_REST_Controller_Testcase {
protected static $post_id;

public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
update_option( 'wp_enable_real_time_collaboration', true );
add_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this after the flip?

Copy link
Member

Choose a reason for hiding this comment

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

Same for a lot of the instances above

Copy link
Author

Choose a reason for hiding this comment

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

We are testing both code paths, both default and when it has been disabled.

I'm adding the filter for both code paths in case we change our mind on opt-in / opt-out. That way, no code changes will be needed.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to have the code changes tbh, but I don't mind either way


self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
self::$subscriber_id = $factory->user->create( array( 'role' => 'subscriber' ) );
Expand All @@ -25,7 +25,7 @@ public static function wpTearDownAfterClass() {
self::delete_user( self::$editor_id );
self::delete_user( self::$subscriber_id );
wp_delete_post( self::$post_id, true );
delete_option( 'wp_enable_real_time_collaboration' );
remove_filter( 'pre_option_wp_disable_real_time_collaboration', '__return_false' );
}

public function set_up() {
Expand Down
117 changes: 113 additions & 4 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ mockedApiResponse.Schema = {
"wp/v2",
"wp-site-health/v1",
"wp-block-editor/v1",
"wp-abilities/v1"
"wp-abilities/v1",
"wp-sync/v1"
],
"authentication": {
"application-passwords": {
Expand Down Expand Up @@ -11157,9 +11158,9 @@ mockedApiResponse.Schema = {
"type": "string",
"required": false
},
"wp_enable_real_time_collaboration": {
"wp_disable_real_time_collaboration": {
"title": "",
"description": "Enable Real-Time Collaboration",
"description": "Disable real-time collaboration",
"type": "boolean",
"required": false
},
Expand Down Expand Up @@ -12770,6 +12771,114 @@ mockedApiResponse.Schema = {
}
}
]
},
"/wp-sync/v1": {
"namespace": "wp-sync/v1",
"methods": [
"GET"
],
"endpoints": [
{
"methods": [
"GET"
],
"args": {
"namespace": {
"default": "wp-sync/v1",
"required": false
},
"context": {
"default": "view",
"required": false
}
}
}
],
"_links": {
"self": [
{
"href": "http://example.org/index.php?rest_route=/wp-sync/v1"
}
]
}
},
"/wp-sync/v1/updates": {
"namespace": "wp-sync/v1",
"methods": [
"POST"
],
"endpoints": [
{
"methods": [
"POST"
],
"args": {
"rooms": {
"items": {
"properties": {
"after": {
"minimum": 0,
"required": true,
"type": "integer"
},
"awareness": {
"required": true,
"type": [
"object",
"null"
]
},
"client_id": {
"minimum": 1,
"required": true,
"type": "integer"
},
"room": {
"required": true,
"type": "string",
"pattern": "^[^/]+/[^/:]+(?::\\S+)?$"
},
"updates": {
"items": {
"properties": {
"data": {
"type": "string",
"required": true
},
"type": {
"type": "string",
"required": true,
"enum": [
"compaction",
"sync_step1",
"sync_step2",
"update"
]
}
},
"required": true,
"type": "object"
},
"minItems": 0,
"required": true,
"type": "array"
}
},
"type": "object"
},
"type": "array",
"required": true
}
}
}
],
"_links": {
"self": [
{
"href": "http://example.org/index.php?rest_route=/wp-sync/v1/updates"
}
]
}
}
},
"image_sizes": {
Expand Down Expand Up @@ -14668,7 +14777,7 @@ mockedApiResponse.settings = {
"use_smilies": true,
"default_category": 1,
"default_post_format": "0",
"wp_enable_real_time_collaboration": false,
"wp_disable_real_time_collaboration": false,
"posts_per_page": 10,
"show_on_front": "posts",
"page_on_front": 0,
Expand Down
Loading