From b801c240e9f06d34a0bc61cfc9b9e1b733f83ece Mon Sep 17 00:00:00 2001 From: zieladam Date: Tue, 24 Mar 2026 12:19:52 +0000 Subject: [PATCH] Real-Time Collaboration: Define WP_ALLOW_COLLABORATION in wp_is_collaboration_allowed() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #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 --- wp-admin/options-writing.php | 12 +++++------ wp-includes/collaboration.php | 36 ++++++++++++++++++++++++++++--- wp-includes/default-constants.php | 20 ----------------- wp-includes/version.php | 2 +- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/wp-admin/options-writing.php b/wp-admin/options-writing.php index c333d19108..d40dc0578b 100644 --- a/wp-admin/options-writing.php +++ b/wp-admin/options-writing.php @@ -112,15 +112,15 @@ unset( $post_formats['standard'] ); - + + +

Note: Real-time collaboration has been disabled.' ); ?>

- - diff --git a/wp-includes/collaboration.php b/wp-includes/collaboration.php index 218f1feda4..11698a2ac7 100644 --- a/wp-includes/collaboration.php +++ b/wp-includes/collaboration.php @@ -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; } /** diff --git a/wp-includes/default-constants.php b/wp-includes/default-constants.php index ab0b3d6cce..acfc878fb7 100644 --- a/wp-includes/default-constants.php +++ b/wp-includes/default-constants.php @@ -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 ); - } - } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 349209715d..daee2896d1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.