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
20 changes: 15 additions & 5 deletions src/wp-admin/options-writing.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,25 @@
<tr>
<th scope="row"><?php _e( 'Collaboration' ); ?></th>
<td>
<?php if ( wp_is_collaboration_allowed() ) : ?>
<?php if ( ! wp_is_collaboration_allowed() ) : ?>
<div class="notice notice-warning inline">
<p><?php _e( '<strong>Note:</strong> Real-time collaboration has been disabled.' ); ?></p>
</div>
<?php elseif ( ! wp_revisions_are_globally_supported() ) : ?>
<div class="notice notice-warning inline">
<p><?php _e( '<strong>Note:</strong> Real-time collaboration requires post revisions. Enable revisions in your site configuration to use collaboration.' ); ?></p>
</div>
<p>
<label for="wp_collaboration_enabled">
<input name="wp_collaboration_enabled_disabled" type="checkbox" id="wp_collaboration_enabled" disabled="disabled" <?php checked( '1', (bool) get_option( 'wp_collaboration_enabled' ) ); ?> />
<?php _e( "Enable early access to real-time collaboration. Real-time collaboration may affect your website's performance." ); ?>
</label>
</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 early access to real-time collaboration. Real-time collaboration may affect your website's performance." ); ?>
</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
28 changes: 27 additions & 1 deletion src/wp-includes/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* 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.
* Collaboration is also disabled when post revisions are turned off
* site-wide (see {@see wp_revisions_are_globally_supported()}).
*
* @since 7.0.0
*
Expand All @@ -20,7 +22,8 @@
function wp_is_collaboration_enabled() {
return (
wp_is_collaboration_allowed() &&
(bool) get_option( 'wp_collaboration_enabled' )
(bool) get_option( 'wp_collaboration_enabled' ) &&
wp_revisions_are_globally_supported()
);
}

Expand Down Expand Up @@ -55,6 +58,29 @@ function wp_is_collaboration_allowed() {
return WP_ALLOW_COLLABORATION;
}

/**
* Determines whether post revisions are enabled site-wide.
*
* When {@see WP_POST_REVISIONS} is false or 0, WordPress does not store
* revisions. Real-time collaboration depends on revision-related flows and
* must remain off in that configuration.
*
* @since 7.0.0
*
* @return bool Whether revisions are globally supported.
*/
function wp_revisions_are_globally_supported() {
if ( ! defined( 'WP_POST_REVISIONS' ) ) {
return true;
}

if ( false === WP_POST_REVISIONS ) {
return false;
}

return 0 !== (int) WP_POST_REVISIONS;
}

/**
* Injects the real-time collaboration setting into a global variable.
*
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/tests/collaboration/wpRevisionsGloballySupported.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Tests for revision-based gating of real-time collaboration.
*
* @package WordPress
* @subpackage Collaboration
*
* @group collaboration
*
* @covers ::wp_revisions_are_globally_supported
* @covers ::wp_is_collaboration_enabled
*/
class Tests_Collaboration_WpRevisionsGloballySupported extends WP_UnitTestCase {

/**
* When WP_POST_REVISIONS is unset, revisions behave as enabled site-wide.
*
* @ticket 77499
*/
public function test_wp_revisions_are_globally_supported_defaults_to_true() {
$this->assertTrue( wp_revisions_are_globally_supported() );
}

/**
* Collaboration follows global revision availability when the option is on.
*
* @ticket 77499
*/
public function test_wp_is_collaboration_enabled_true_when_option_enabled_and_revisions_supported() {
update_option( 'wp_collaboration_enabled', 1 );

$this->assertTrue( wp_revisions_are_globally_supported() );
$this->assertTrue( wp_is_collaboration_enabled() );
}
}
Loading