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
12 changes: 8 additions & 4 deletions src/wp-admin/options-writing.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@
<tr>
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
<td>
<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 if ( ! WP_ALLOW_COLLABORATION ) : ?>
<p class="notice notice-warning inline"><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
<?php else : ?>
<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 endif; ?>
</td>
</tr>
<?php
Expand Down
21 changes: 20 additions & 1 deletion src/wp-includes/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
* @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() {
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || ! WP_ALLOW_COLLABORATION ) {
return false;
}

return (bool) get_option( 'wp_collaboration_enabled' );
}

/**
* Injects the real-time collaboration setting into a global variable.
*
Expand All @@ -18,7 +37,7 @@
function wp_collaboration_inject_setting() {
global $pagenow;

if ( ! (bool) get_option( 'wp_collaboration_enabled' ) ) {
if ( ! wp_is_collaboration_enabled() ) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions src/wp-includes/default-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ 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 ) {
define( 'WP_ALLOW_COLLABORATION', 'true' === $env_value );
} else {
// Environment variable is not defined, default to true.
define( 'WP_ALLOW_COLLABORATION', true );
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ function create_initial_post_types() {
)
);

if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
if ( wp_is_collaboration_enabled() ) {
register_post_type(
'wp_sync_storage',
array(
Expand Down Expand Up @@ -8672,7 +8672,7 @@ function wp_create_initial_post_meta() {
)
);

if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
if ( wp_is_collaboration_enabled() ) {
register_meta(
'post',
'_crdt_document',
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function create_initial_rest_routes() {
$icons_controller->register_routes();

// Collaboration.
if ( (bool) get_option( 'wp_collaboration_enabled' ) ) {
if ( wp_is_collaboration_enabled() ) {
$sync_storage = new WP_Sync_Post_Meta_Storage();
$sync_server = new WP_HTTP_Polling_Sync_Server( $sync_storage );
$sync_server->register_routes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function create_item( $request ) {
* the saved post. This diff is then applied to the in-memory CRDT
* document, which can lead to duplicate inserts or deletions.
*/
$is_collaboration_enabled = (bool) get_option( 'wp_collaboration_enabled' );
$is_collaboration_enabled = wp_is_collaboration_enabled();

if ( $is_draft && (int) $post->post_author === $user_id && ! $post_lock && ! $is_collaboration_enabled ) {
/*
Expand Down
Loading