Skip to content

Work with real-time collaboration: Replace custom Redux store with core entity store#1217

Merged
GaryJones merged 3 commits into
developfrom
issue-1204
Apr 22, 2026
Merged

Work with real-time collaboration: Replace custom Redux store with core entity store#1217
GaryJones merged 3 commits into
developfrom
issue-1204

Conversation

@smithjw1

@smithjw1 smithjw1 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Rationale

Real-time collaboration observes the core data store to sync entities among collaborators. By switching the storage mechanism, Co-Authors Plus becomes compatible with real-time collaboration. This only affects how co-authors are manipulated and saved in the editor. The underlying data shape stays the same.

Description

Replaces the custom cap/authors Redux store and subscribe()-based save mechanism with WordPress's core entity store (getEditedPostAttribute / editPost). Co-author taxonomy term IDs now flow through the standard post entity.

Adds a new authors-by-term-ids REST endpoint so the editor sidebar can resolve term IDs to rich author data, a useCoauthorDetails hook with request-scoped caching, and PHP-side bridging logic (sync_coauthors_on_rest_save, backfill_coauthor_terms_in_rest) to keep post_author in sync and fire deprecation notices for legacy filters.

Closes #1204

Deploy Notes

No new dependencies. The prop-types import was removed from the JS side. The custom cap/authors data store is no longer registered — any third-party code relying on select('cap/authors') will need to migrate to the core entity store.

Steps to Test

  1. Check out PR and run npm run build.
  2. Open the block editor for a post with multiple co-authors — verify authors load in the sidebar panel.
  3. Add/remove/reorder co-authors, save the post, and reload — verify changes persist.
  4. Create a brand-new post (auto-draft) — verify the current user is assigned as the default co-author.
  5. Open a legacy post (created before Co-Authors Plus was active) — verify the post_author is backfilled as a co-author term.
  6. Verify post_author stays in sync with the first co-author after saves.

…thors

Replace the custom `cap/authors` Redux store and subscribe-based save mechanism
with WordPress's core entity store (`getEditedPostAttribute` / `editPost`). This
lets the block editor treat co-author taxonomy terms as first-class post data,
removing the need for a separate save side-channel.

Key changes:

- Register the `author` taxonomy in the REST API so term IDs flow through the
  core entity store automatically.
- Add `authors-by-term-ids` REST endpoint to resolve term IDs to rich author
  data for the editor sidebar.
- Add `useCoauthorDetails` hook (with request-scoped caching) to replace the
  old store resolver.
- Bridge REST saves to `add_coauthors()` via `rest_after_insert_{post_type}` so
  `post_author` sync and legacy filters continue to work.
- Backfill empty coauthor terms from `post_author` in REST responses for posts
  that predate the plugin, gated behind `current_user_can('edit_post')`.
- Fire deprecation notices for `coauthors_post_list_pluck_field` and
  `coauthors_post_get_coauthor_by_field` filters during REST saves.
- Delete `src/store.js` and the `subscribe()`-based save loop in `src/index.js`.

Closes #1204

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@smithjw1 smithjw1 requested a review from a team as a code owner March 24, 2026 20:28
@GaryJones

Copy link
Copy Markdown
Contributor

I'll defer to @douglas-johnson , @leogermani , @claudiulodro for the review, but a key bit that's missing is the rationale behind this proposed change.

@smithjw1 smithjw1 changed the title Replace custom Redux store with core entity store for co-authors Work with real-time collaboration: Replace custom Redux store with core entity store Mar 25, 2026
@smithjw1

Copy link
Copy Markdown
Contributor Author

... but a key bit that's missing is the rationale behind this proposed change.

Great point @GaryJones. I've updated the title and added a rationale section. Sorry, I knew why I was doing it, but that isn't clear to everyone looking at the PR.

@leogermani

Copy link
Copy Markdown
Contributor

Thanks @smithjw1 , I think this change makes sense and is a good move. We just need to test it thoroughly and evaluate the extent of the impact on things that we and other people might be relying on... We'll have a closer look!

@leogermani

Copy link
Copy Markdown
Contributor

Real-time collaboration observes the core data store to sync entities among collaborators. By switching the storage mechanism, Co-Authors Plus becomes compatible with real-time collaboration.

Can you expand on what exactly doesn't work?

In the current state if multiple people try to change authors at the same time they will override each others changes? Is that what we are solving?

Or is the idea that collaborative editing will automatically assign a person as a co-author when they make edits to it?

@smithjw1

Copy link
Copy Markdown
Contributor Author

In the current state if multiple people try to change authors at the same time they will override each others changes? Is that what we are solving?

Yes, that's what happens. Today, if User A and User B are both editing, the "last save wins." With this change, updates made by User B will be immediately reflected to User A.

@douglas-johnson

Copy link
Copy Markdown
Contributor

I tested in a full site editor theme and a hybrid theme with WordPress 7.0-RC2. I did not experience any issues while using the sidebar to add / update co-authors in the post editor or using the co-author blocks in the site editor.

@leogermani leogermani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks really good and is a great improvement regardless of collaborative editing. Using term-id in the front end was a good idea to avoid ID collisions between authors and guest authors.

I gave it a full round of testing and it seems to be working fine. I left only two minor comments... I'm still unsure if this can have any bugs with really old guest authors because of what I see here. But I think it's fine.

I'll ask some help to review the JS/Store piece of it from more experienced folks on that front.

One thing I know is that this will break any integrations that are relying on the CAP's store for some reason. I know we are. But we can fix it.

Comment thread php/class-coauthors-endpoint.php Outdated
Comment thread php/class-coauthors-plus.php Outdated

@chickenn00dle chickenn00dle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just noting I had a look at the JS changes which look good. I left two non-blocking comments. Feel free to ignore.

Comment thread src/components/co-authors/index.jsx Outdated
Comment thread src/components/co-authors/index.jsx Outdated
- Remove unnecessary `cap-` prefix stripping in get_coauthors_by_term_ids()
  and sync_coauthors_on_rest_save() — get_coauthor_by() already handles
  this via get_post_meta_key().
- Remove unused hasFinishedResolution destructure from useSelect.
- Use `coauthors !== undefined` instead of `!! postId` to determine
  whether the post entity has resolved, ensuring attributes are available.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@smithjw1

Copy link
Copy Markdown
Contributor Author

I've addressed the PR comments to date, but it would be good to get this out there and tested before releasing a breaking change.

What's the best way to communicate that to plugin users?

@smithjw1

Copy link
Copy Markdown
Contributor Author

@GaryJones I should have addressed this question to you:

I've addressed the PR comments to date, but it would be good to get this out there and tested before releasing a breaking change.

What's the best way to communicate that to plugin users?

@GaryJones

Copy link
Copy Markdown
Contributor

@smithjw1 We can tag a beta/RC release, and you can send the link to whichever customers you think are willing to test.

@smithjw1

Copy link
Copy Markdown
Contributor Author

@smithjw1 We can tag a beta/RC release, and you can send the link to whichever customers you think are willing to test.

Forgive my ignorance, but is merging this to the develop branch the first step in that process? Having never run a release of this plugin, I'm unsure.

The two _deprecated_hook() calls guarding coauthors_post_list_pluck_field
and coauthors_post_get_coauthor_by_field originally named Co-Authors Plus
3.8 as the deprecation version, on the assumption that this change would
land in the next minor release. The store switch in this PR is a breaking
change for consumers that read from the cap/authors Redux store directly
(Newspack being a known case), so the release has been re-scoped to 4.0.

The version argument to _deprecated_hook() is what WordPress surfaces to
developers via deprecation warnings, so it must accurately name the
release in which the deprecation actually lands — otherwise plugin
authors chasing the warning will look for a 3.8 release that never
existed.
@GaryJones

Copy link
Copy Markdown
Contributor

With Gutenberg v23, and two tabs open (Eddie the Editor, and Admin the Administrator), I was able to show that updating of co-authors was reflected in RTC.

Screen.Recording.2026-04-23.at.00.31.19.mov

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.

Update for compatibility with real-time collaboration

5 participants