Make WordPress Core

Changeset 62100


Ignore:
Timestamp:
03/24/2026 12:18:06 PM (7 months ago)
Author:
zieladam
Message:

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.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-writing.php

    r62078 r62100  
    113113<th scope="row"><?php _e( 'Collaboration' ); ?></th>
    114114<td>
    115         <?php if ( defined( 'WP_ALLOW_COLLABORATION' ) && false === WP_ALLOW_COLLABORATION ) : ?>
     115        <?php if ( wp_is_collaboration_allowed() ) : ?>
     116                <label for="wp_collaboration_enabled">
     117                        <input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
     118                        <?php _e( "Enable early access to real-time collaboration. Real-time collaboration may affect your website's performance." ); ?>
     119                </label>
     120        <?php else : ?>
    116121                <div class="notice notice-warning inline">
    117122                        <p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
    118123                </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>
    124124        <?php endif; ?>
    125125</td>
  • trunk/src/wp-includes/collaboration.php

    r62075 r62100  
    1919 */
    2020function 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 */
     39function 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
  • trunk/src/wp-includes/default-constants.php

    r62075 r62100  
    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
Note: See TracChangeset for help on using the changeset viewer.