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 https://github.com/WordPress/wordpress-develop/pull/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
This commit is contained in:
zieladam
2026-03-24 12:19:52 +00:00
parent b73fefa893
commit b801c240e9
4 changed files with 40 additions and 30 deletions

View File

@@ -112,15 +112,15 @@ unset( $post_formats['standard'] );
<tr>
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
<td>
<?php if ( defined( 'WP_ALLOW_COLLABORATION' ) && false === WP_ALLOW_COLLABORATION ) : ?>
<?php if ( wp_is_collaboration_allowed() ) : ?>
<label for="wp_collaboration_enabled">
<input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
<?php _e( "Enable early access to real-time collaboration. Real-time collaboration may affect your website's performance." ); ?>
</label>
<?php else : ?>
<div class="notice notice-warning inline">
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
</div>
<?php else : ?>
<label for="wp_collaboration_enabled">
<input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
<?php _e( 'Enable real-time collaboration' ); ?>
</label>
<?php endif; ?>
</td>
</tr>

View File

@@ -18,11 +18,41 @@
* @return bool Whether real-time collaboration is enabled.
*/
function wp_is_collaboration_enabled() {
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || ! WP_ALLOW_COLLABORATION ) {
return false;
return (
wp_is_collaboration_allowed() &&
(bool) get_option( 'wp_collaboration_enabled' )
);
}
/**
* Determines whether real-time collaboration is allowed.
*
* If the WP_ALLOW_COLLABORATION constant is false,
* collaboration is not allowed and cannot be enabled.
* The constant defaults to true, unless the WP_ALLOW_COLLABORATION
* environment variable is set to string "false".
*
* @since 7.0.0
*
* @return bool Whether real-time collaboration is enabled.
*/
function wp_is_collaboration_allowed() {
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
$env_value = getenv( 'WP_ALLOW_COLLABORATION' );
if ( false === $env_value ) {
// Environment variable is not defined, default to allowing collaboration.
define( 'WP_ALLOW_COLLABORATION', true );
} else {
/*
* Environment variable is defined, let's confirm it is actually set to
* "true" as it may still have a string value "false" the preceeding
* `if` branch only tests for the boolean `false`.
*/
define( 'WP_ALLOW_COLLABORATION', 'true' === $env_value );
}
}
return (bool) get_option( 'wp_collaboration_enabled' );
return WP_ALLOW_COLLABORATION;
}
/**

View File

@@ -398,26 +398,6 @@ function wp_functionality_constants() {
if ( ! defined( 'WP_CRON_LOCK_TIMEOUT' ) ) {
define( 'WP_CRON_LOCK_TIMEOUT', MINUTE_IN_SECONDS );
}
/**
* Whether real time collaboration is permitted to be enabled.
*
* @since 7.0.0
*/
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
$env_value = getenv( 'WP_ALLOW_COLLABORATION' );
if ( false === $env_value ) {
// Environment variable is not defined, default to allowing collaboration.
define( 'WP_ALLOW_COLLABORATION', true );
} else {
/*
* Environment variable is defined, let's confirm it is actually set to
* "true" as it may still have a string value "false" the preceeding
* `if` branch only tests for the boolean `false`.
*/
define( 'WP_ALLOW_COLLABORATION', 'true' === $env_value );
}
}
}
/**

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-beta6-62099';
$wp_version = '7.0-beta6-62100';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.