Skip to content

Add WP_ALLOW_COLLABORATION constant#11311

Closed
alecgeatches wants to merge 8 commits intoWordPress:trunkfrom
alecgeatches:add/disable-collaboration-flag
Closed

Add WP_ALLOW_COLLABORATION constant#11311
alecgeatches wants to merge 8 commits intoWordPress:trunkfrom
alecgeatches:add/disable-collaboration-flag

Conversation

@alecgeatches
Copy link

@alecgeatches alecgeatches commented Mar 19, 2026

Update from @ingeniumed:

Noting that it's now WP_ALLOW_COLLABORATION wherein:

true - this means collaboration can be turned on false - this means collaboration cannot be turned on not defined - this means collaboration can be turned on

It can be defined in a way to allow hosts to disallow the feature at an environment level.

Trac ticket: https://core.trac.wordpress.org/ticket/64904

Screenshots

With

define( 'WP_ALLOW_COLLABORATION', false );
Screenshot 2026-03-19 at 3 13 13 PM

With

define( 'WP_ALLOW_COLLABORATION', true );

or no WP_ALLOW_COLLABORATION configuration at all, the default checkbox:

Screenshot 2026-03-19 at 3 13 28 PM

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Opus 4.6
Used for: Implementation

@github-actions
Copy link

github-actions bot commented Mar 19, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props alecgeatches, ingeniumed, zieladam, peterwilsoncc, tyxla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few of suggestions.

  1. Instead of a constant with a negative intent, it is clearer to use a positive intent. This avoids having code along the lines of if ( CONSTANT === true ) then false;
  2. It's more precise to describe the constant as whether or not RTC is permitted, than whether RTC is enabled or disabled. I think WP_ALLOW_COLLABORATION is a better match for that intent.
  3. As a part of the consideration is to allow hosts to disallow the feature at an environment level, allowing an environment variable to be set will help meet their needs
  4. Instead of needing to repeat the ! defined() && ..., define the default value in wp_functionality_constants()

My suggestion is to add the following to wp_functionality_constants() and modify the PR for the various implications

/**
 * Whether real time collaboration is permitted to be enabled.
 *
 * @since 7.0.0
 */
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
	if ( false !== getenv( 'WP_ALLOW_COLLABORATION' ) ) {
		// Environment variable is defined.
		if ( 'true' === getenv( 'WP_ALLOW_COLLABORATION' ) ) {
			define( 'WP_ALLOW_COLLABORATION', true );
		} else {
			define( 'WP_ALLOW_COLLABORATION', false );
		}
	} else {
		// Environment variable is not defined, default to true.
		define( 'WP_ALLOW_COLLABORATION', true );
	}
}

@ingeniumed
Copy link

I have a few of suggestions.

  1. Instead of a constant with a negative intent, it is clearer to use a positive intent. This avoids having code along the lines of if ( CONSTANT === true ) then false;
  2. It's more precise to describe the constant as whether or not RTC is permitted, than whether RTC is enabled or disabled. I think WP_ALLOW_COLLABORATION is a better match for that intent.
  3. As a part of the consideration is to allow hosts to disallow the feature at an environment level, allowing an environment variable to be set will help meet their needs
  4. Instead of needing to repeat the ! defined() && ..., define the default value in wp_functionality_constants()

My suggestion is to add the following to wp_functionality_constants() and modify the PR for the various implications

/**
 * Whether real time collaboration is permitted to be enabled.
 *
 * @since 7.0.0
 */
if ( ! defined( 'WP_ALLOW_COLLABORATION' ) ) {
	if ( false !== getenv( 'WP_ALLOW_COLLABORATION' ) ) {
		// Environment variable is defined.
		if ( 'true' === getenv( 'WP_ALLOW_COLLABORATION' ) ) {
			define( 'WP_ALLOW_COLLABORATION', true );
		} else {
			define( 'WP_ALLOW_COLLABORATION', false );
		}
	} else {
		// Environment variable is not defined, default to true.
		define( 'WP_ALLOW_COLLABORATION', true );
	}
}

Thanks for the feedback @peterwilsoncc. I've updated the code with that in mind.

I did have to leave the defined check in collaboration.php as it was erroring out without that.

Let me know what you think of the updated code 🙏🏾

@ingeniumed
Copy link

Noting that it's now WP_ALLOW_COLLABORATION wherein:

true - this means collaboration can be turned on
false - this means collaboration cannot be turned on
not defined - this means collaboration can be turned on

It can be defined in a way to allow hosts to disallow the feature at an environment level.

@alecgeatches alecgeatches changed the title Add WP_DISABLE_COLLABORATION constant Add WP_ALLOW_COLLABORATION constant Mar 20, 2026
Comment on lines +12 to +14
* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a potential edge case to verify here: if wp_is_collaboration_enabled() is called before WP_ALLOW_COLLABORATION is defined, RTC will also be disabled regardless of the database option.

Can we verify that this function can't be called before the constant is defined? If we can't verify this, or we found a way to call wp_is_collaboration_enabled() before the constant was declared, can we amend the docs to make this edge case clear?

Copy link
Contributor

@adamziel adamziel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant is defined in wp_functionality_constants(); which is called in wp-settings.php (after require "collaboration.php") so the premature reference would have to happen at some point in the WordPress boot flow before that call (or via SHORTINIT). Two possible solutions I see are:

  • Accept that edge-case, since the same gotcha is true for other constants defined in that function: AUTOSAVE_INTERVAL, EMPTY_TRASH_DAYS, WP_POST_REVISIONS, and WP_CRON_LOCK_TIMEOUT.
  • Define the constant before the function is defined, e.g. directly in collaboration.php, maybe even inside of that function if it's not defined by the time of the call. That would look something like this:
function wp_is_collaboration_enabled() {
	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 );
		}
	}

	if ( ! WP_ALLOW_COLLABORATION ) {
		return false
	}

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

Which would be fine with me. There's a precedence of a similar behavior in kses.php:

https://github.com/alecgeatches/wordpress-develop/blob/be03ad089eae148e2d95e429579022bef69c77c9/src/wp-includes/kses.php#L32-L53

Copy link
Contributor

@adamziel adamziel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we keep this part as it is for beta6 and revisit it in RC1 cc @ellatrix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming that this makes sense to me 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant is defined in wp_functionality_constants(); which is called in wp-settings.php (after require "collaboration.php") so the premature reference would have to happen at some point in the WordPress boot flow before that call (or via SHORTINIT). Two possible solutions I see are:

Thanks for catching this, I hadn't noticed the order of operations.

Of the two suggestions I think defining the constant in wp_is_collaboration_enabled() is the safest approach for RC1. @adamziel are you able to look in to this in #11322 (I'm at a mate's 50th today so won't have a chance, sorry).

<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 ) : ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also have a defined() check before we actually use the constant, just in case someone is loading the writing settings admin page in an unconventional way.

Copy link
Contributor

@adamziel adamziel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

Suggested change
<?php if ( ! WP_ALLOW_COLLABORATION ) : ?>
<?php if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || true === WP_ALLOW_COLLABORATION ) : ?>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take the liberty of merging the suggestion. Feel free to rollback my commit if needed.

Copy link
Member

@tyxla tyxla Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel this seems wrong; did you mean:

<?php if ( ! defined( 'WP_ALLOW_COLLABORATION' ) || false === WP_ALLOW_COLLABORATION ) : ?>

If we make it true we're inverting what we had there before, which looks unintentional.

Copy link
Contributor

@adamziel adamziel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was "if collaboration is allowed, allow the user to decide whether they want to use it". Yours reads to me like "If collaboration is implicitly allowed by not defining the constant OR the collaboration is explicitly not allowed, then allow the user to decide" which seems off to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, you're right and I'm wrong. Good spot. I'll open a PR to correct this, CC @ellatrix

@adamziel
Copy link
Contributor

wp_functionality_constants() doesn't seem to be called during SHORTINIT, so any code path that refers to WP_ALLOW_COLLABORATION will fail with:

Fatal error: Uncaught Error: Undefined constant "WP_ALLOW_COLLABORATION" in

What would be the best way to document that? While the same is true for AUTOSAVE_INTERVAL and other constants defined in wp_functionality_constants(), WP_ALLOW_COLLABORATION seems to have some potential to pop up in different places around the PHP codebase.

Copy link
Contributor

@adamziel adamziel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and works as intended. Note: I've merged a few suggestions @tyxla and I proposed. I know it's not the typical workflow, but I took that liberty in the name of beta 6. I think they're good additions and I'm also happy for any of them to be reverted as needed.

pento pushed a commit that referenced this pull request Mar 20, 2026
This provides an easy way at config level to disable real-time collaboration.

Developed in: #11311.

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


git-svn-id: https://develop.svn.wordpress.org/trunk@62075 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Mar 20, 2026
This provides an easy way at config level to disable real-time collaboration.

Developed in: WordPress/wordpress-develop#11311.

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

Built from https://develop.svn.wordpress.org/trunk@62075


git-svn-id: http://core.svn.wordpress.org/trunk@61357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@ellatrix
Copy link
Member

Closing since it's been committed

@ellatrix ellatrix closed this Mar 20, 2026
adamziel added a commit to adamziel/wordpress-develop that referenced this pull request Mar 20, 2026
The WP_ALLOW_COLLABORATION constant was introduced in PR WordPress#11311 to support
disabling RTC at the host level or at the wp-config.php level.
A part of that PR was hiding the "Enable RTC" checkbox in the
writing options when RTC is explicitly disallowed via the
constant. In the process of reviewing the change and merging
suggestions, I have used the wrong condition to hide that
checkbox.

This PR makes the condition right.

Props to @tyxla for noticing!

\# Testing instructions

* Set the WP_ALLOW_COLLABORATION constant to false, go to writing options, confirm the checkbox is replaced by a message "Real-time collaboration has been disabled".
* Set it to true, confirm the checkbox is there.
* Remove the constnat, confirm the checkbox is there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants