Make WordPress Core

Changeset 62075


Ignore:
Timestamp:
03/20/2026 03:25:02 PM (2 months ago)
Author:
ellatrix
Message:

Real-time collaboration: Add WP_ALLOW_COLLABORATION constant.

This provides an easy way at config level to disable real-time collaboration.

Developed in: https://github.com/WordPress/wordpress-develop/pull/11311.

See #64904.
Props alecgeatches, ingeniumed, zieladam, peterwilsoncc, tyxla.

Location:
trunk/src
Files:
6 edited

Legend:

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

    r62058 r62075  
    113113<th scope="row"><?php _e( 'Collaboration' ); ?></th>
    114114<td>
    115     <label for="wp_collaboration_enabled">
    116         <input name="wp_collaboration_enabled" type="checkbox" id="wp_collaboration_enabled" value="1" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
    117         <?php _e( 'Enable real-time collaboration' ); ?>
    118     </label>
     115    <?php if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || true === 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 : ?>
     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>
     124    <?php endif; ?>
    119125</td>
    120126</tr>
  • trunk/src/wp-includes/collaboration.php

    r62058 r62075  
    66 * @since 7.0.0
    77 */
     8
     9/**
     10 * Determines whether real-time collaboration is enabled.
     11 *
     12 * If the WP_ALLOW_COLLABORATION constant is false,
     13 * collaboration is always disabled regardless of the database option.
     14 * Otherwise, falls back to the 'wp_collaboration_enabled' option.
     15 *
     16 * @since 7.0.0
     17 *
     18 * @return bool Whether real-time collaboration is enabled.
     19 */
     20function wp_is_collaboration_enabled() {
     21    if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || ! WP_ALLOW_COLLABORATION ) {
     22        return false;
     23    }
     24
     25    return (bool) get_option( 'wp_collaboration_enabled' );
     26}
    827
    928/**
     
    1938    global $pagenow;
    2039
    21     if ( ! (bool) get_option( 'wp_collaboration_enabled' ) ) {
     40    if ( ! wp_is_collaboration_enabled() ) {
    2241        return;
    2342    }
  • trunk/src/wp-includes/default-constants.php

    r59146 r62075  
    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    }
    401421}
    402422
  • trunk/src/wp-includes/post.php

    r62058 r62075  
    658658    );
    659659
    660     if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
     660    if ( wp_is_collaboration_enabled() ) {
    661661        register_post_type(
    662662            'wp_sync_storage',
     
    86738673    );
    86748674
    8675     if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
     8675    if ( wp_is_collaboration_enabled() ) {
    86768676        register_meta(
    86778677            'post',
  • trunk/src/wp-includes/rest-api.php

    r62058 r62075  
    431431
    432432    // Collaboration.
    433     if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
     433    if ( wp_is_collaboration_enabled() ) {
    434434        $sync_storage = new WP_Sync_Post_Meta_Storage();
    435435        $sync_server  = new WP_HTTP_Polling_Sync_Server( $sync_storage );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php

    r62058 r62075  
    255255         *   document, which can lead to duplicate inserts or deletions.
    256256         */
    257         $is_collaboration_enabled = (bool) get_option( 'wp_collaboration_enabled' );
     257        $is_collaboration_enabled = wp_is_collaboration_enabled();
    258258
    259259        if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
Note: See TracChangeset for help on using the changeset viewer.