Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/wp-admin/options-writing.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@
<tr>
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
<td>
<?php if ( defined( 'WP_ALLOW_COLLABORATION' ) && false === WP_ALLOW_COLLABORATION ) : ?>
<div class="notice notice-warning inline">
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
</div>
<?php else : ?>
<?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 real-time collaboration' ); ?>
</label>
<?php else : ?>
<div class="notice notice-warning inline">
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
</div>
<?php endif; ?>
</td>
</tr>
Expand Down
36 changes: 33 additions & 3 deletions src/wp-includes/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
20 changes: 0 additions & 20 deletions src/wp-includes/default-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}

/**
Expand Down
Loading