Files
wordpress/wp-includes/collaboration.php
zieladam b801c240e9 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
2026-03-24 12:19:52 +00:00

86 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Bootstraps collaborative editing.
*
* @package WordPress
* @since 7.0.0
*/
/**
* Determines whether real-time collaboration is enabled.
*
* If the WP_ALLOW_COLLABORATION constant is false,
* collaboration is always disabled regardless of the database option.
* Otherwise, falls back to the 'wp_collaboration_enabled' option.
*
* @since 7.0.0
*
* @return bool Whether real-time collaboration is enabled.
*/
function wp_is_collaboration_enabled() {
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 WP_ALLOW_COLLABORATION;
}
/**
* Injects the real-time collaboration setting into a global variable.
*
* @since 7.0.0
*
* @access private
*
* @global string $pagenow The filename of the current screen.
*/
function wp_collaboration_inject_setting() {
global $pagenow;
if ( ! wp_is_collaboration_enabled() ) {
return;
}
// Disable real-time collaboration on the site editor.
$enabled = true;
if ( 'site-editor.php' === $pagenow ) {
$enabled = false;
}
wp_add_inline_script(
'wp-core-data',
'window._wpCollaborationEnabled = ' . wp_json_encode( $enabled ) . ';',
'after'
);
}