Skip to content

Commit b801c24

Browse files
committed
Real-Time Collaboration: Define WP_ALLOW_COLLABORATION in wp_is_collaboration_allowed()
#62075 introduced the WP_ALLOW_COLLABORATION constant to help hosts disable RTC at the platform level. The constant was defined in wp_functionality_constants(), which runs in wp-settings.php after collaboration.php is loaded. That created a boot-order edge case where wp_is_collaboration_enabled() could be called before the constant existed – for instance via SHORTINIT. This commit moves the constant definition into a new wp_is_collaboration_allowed() function in collaboration.php. The function checks the constant, and if it's missing, defines it on the spot from the environment variable (defaulting to true). wp_is_collaboration_enabled() now delegates to wp_is_collaboration_allowed() for the constant check, and the admin UI calls wp_is_collaboration_allowed() directly to decide whether to show the checkbox or a "disabled" notice. It also slightly improves the label of the "enable RTC" checkbox on the settings page. Props peterwilsoncc, mcsf, joen, ingeniumed. Developed in WordPress/wordpress-develop#11333. See #64904. Built from https://develop.svn.wordpress.org/trunk@62100 git-svn-id: http://core.svn.wordpress.org/trunk@61382 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent b73fefa commit b801c24

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

wp-admin/options-writing.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@
112112
<tr>
113113
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
114114
<td>
115-
<?php if ( defined( 'WP_ALLOW_COLLABORATION' ) && false === 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 : ?>
115+
<?php if ( wp_is_collaboration_allowed() ) : ?>
120116
<label for="wp_collaboration_enabled">
121117
<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' ); ?>
118+
<?php _e( "Enable early access to real-time collaboration. Real-time collaboration may affect your website's performance." ); ?>
123119
</label>
120+
<?php else : ?>
121+
<div class="notice notice-warning inline">
122+
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
123+
</div>
124124
<?php endif; ?>
125125
</td>
126126
</tr>

wp-includes/collaboration.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,41 @@
1818
* @return bool Whether real-time collaboration is enabled.
1919
*/
2020
function wp_is_collaboration_enabled() {
21-
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || ! WP_ALLOW_COLLABORATION ) {
22-
return false;
21+
return (
22+
wp_is_collaboration_allowed() &&
23+
(bool) get_option( 'wp_collaboration_enabled' )
24+
);
25+
}
26+
27+
/**
28+
* Determines whether real-time collaboration is allowed.
29+
*
30+
* If the WP_ALLOW_COLLABORATION constant is false,
31+
* collaboration is not allowed and cannot be enabled.
32+
* The constant defaults to true, unless the WP_ALLOW_COLLABORATION
33+
* environment variable is set to string "false".
34+
*
35+
* @since 7.0.0
36+
*
37+
* @return bool Whether real-time collaboration is enabled.
38+
*/
39+
function wp_is_collaboration_allowed() {
40+
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
41+
$env_value = getenv( 'WP_ALLOW_COLLABORATION' );
42+
if ( false === $env_value ) {
43+
// Environment variable is not defined, default to allowing collaboration.
44+
define( 'WP_ALLOW_COLLABORATION', true );
45+
} else {
46+
/*
47+
* Environment variable is defined, let's confirm it is actually set to
48+
* "true" as it may still have a string value "false" – the preceeding
49+
* `if` branch only tests for the boolean `false`.
50+
*/
51+
define( 'WP_ALLOW_COLLABORATION', 'true' === $env_value );
52+
}
2353
}
2454

25-
return (bool) get_option( 'wp_collaboration_enabled' );
55+
return WP_ALLOW_COLLABORATION;
2656
}
2757

2858
/**

wp-includes/default-constants.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -398,26 +398,6 @@ 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-
}
421401
}
422402

423403
/**

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-beta6-62099';
19+
$wp_version = '7.0-beta6-62100';
2020

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

0 commit comments

Comments
 (0)