Skip to content

Commit c6e0d45

Browse files
committed
Real-time collaboration: Add WP_ALLOW_COLLABORATION constant.
This provides an easy way at config level to disable real-time collaboration. Developed in: WordPress/wordpress-develop#11311. See #64904. Props alecgeatches, ingeniumed, zieladam, peterwilsoncc, tyxla. Built from https://develop.svn.wordpress.org/trunk@62075 git-svn-id: http://core.svn.wordpress.org/trunk@61357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 87c17b8 commit c6e0d45

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

wp-admin/options-writing.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,16 @@
112112
<tr>
113113
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
114114
<td>
115-
<label for="wp_collaboration_enabled">
116-
<input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
117-
<?php _e( 'Enable real-time collaboration' ); ?>
118-
</label>
115+
<?php if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || true === WP_ALLOW_COLLABORATION ) : ?>
116+
<div class="notice notice-warning inline">
117+
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
118+
</div>
119+
<?php else : ?>
120+
<label for="wp_collaboration_enabled">
121+
<input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
122+
<?php _e( 'Enable real-time collaboration' ); ?>
123+
</label>
124+
<?php endif; ?>
119125
</td>
120126
</tr>
121127
<?php

wp-includes/collaboration.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
* @since 7.0.0
77
*/
88

9+
/**
10+
* Determines whether real-time collaboration is enabled.
11+
*
12+
* If the WP_ALLOW_COLLABORATION constant is false,
13+
* collaboration is always disabled regardless of the database option.
14+
* Otherwise, falls back to the 'wp_collaboration_enabled' option.
15+
*
16+
* @since 7.0.0
17+
*
18+
* @return bool Whether real-time collaboration is enabled.
19+
*/
20+
function wp_is_collaboration_enabled() {
21+
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || ! WP_ALLOW_COLLABORATION ) {
22+
return false;
23+
}
24+
25+
return (bool) get_option( 'wp_collaboration_enabled' );
26+
}
27+
928
/**
1029
* Injects the real-time collaboration setting into a global variable.
1130
*
@@ -18,7 +37,7 @@
1837
function wp_collaboration_inject_setting() {
1938
global $pagenow;
2039

21-
if ( ! (bool) get_option( 'wp_collaboration_enabled' ) ) {
40+
if ( ! wp_is_collaboration_enabled() ) {
2241
return;
2342
}
2443

wp-includes/default-constants.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,26 @@ function wp_functionality_constants() {
398398
if ( ! defined( 'WP_CRON_LOCK_TIMEOUT' ) ) {
399399
define( 'WP_CRON_LOCK_TIMEOUT', MINUTE_IN_SECONDS );
400400
}
401+
402+
/**
403+
* Whether real time collaboration is permitted to be enabled.
404+
*
405+
* @since 7.0.0
406+
*/
407+
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
408+
$env_value = getenv( 'WP_ALLOW_COLLABORATION' );
409+
if ( false === $env_value ) {
410+
// Environment variable is not defined, default to allowing collaboration.
411+
define( 'WP_ALLOW_COLLABORATION', true );
412+
} else {
413+
/*
414+
* Environment variable is defined, let's confirm it is actually set to
415+
* "true" as it may still have a string value "false" – the preceeding
416+
* `if` branch only tests for the boolean `false`.
417+
*/
418+
define( 'WP_ALLOW_COLLABORATION', 'true' === $env_value );
419+
}
420+
}
401421
}
402422

403423
/**

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 ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
660+
if ( wp_is_collaboration_enabled() ) {
661661
register_post_type(
662662
'wp_sync_storage',
663663
array(
@@ -8672,7 +8672,7 @@ function wp_create_initial_post_meta() {
86728672
)
86738673
);
86748674

8675-
if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
8675+
if ( wp_is_collaboration_enabled() ) {
86768676
register_meta(
86778677
'post',
86788678
'_crdt_document',

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 ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
433+
if ( wp_is_collaboration_enabled() ) {
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();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ 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_enabled = (bool) get_option( 'wp_collaboration_enabled' );
257+
$is_collaboration_enabled = wp_is_collaboration_enabled();
258258

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

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-beta5-62074';
19+
$wp_version = '7.0-beta5-62075';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)