Skip to content

Comments: Notify mentioned users and thread followers for Notes @mentions#12548

Open
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/notes-mention-notifications
Open

Comments: Notify mentioned users and thread followers for Notes @mentions#12548
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/notes-mention-notifications

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jul 15, 2026

Copy link
Copy Markdown
Member

Backports the notification layer from the Gutenberg Notes @mention work (WordPress/gutenberg#79606, still open upstream). Split out of #12503, which now covers only the kses allowance (the merged WordPress/gutenberg#79604 and WordPress/gutenberg#80221).

Trac ticket: #65639. The kses half remains on #65622.

Upstream status: the source Gutenberg PR (#79606) has not merged yet, so this backport should not land until it does.

What

On rest_insert_comment for note comments (alongside the existing post-author notification), wp_notify_note_mentions():

  1. Parses mentions out of the saved content via wp_get_note_mentioned_user_ids(): only anchors carrying both the wp-note-mention class and a user-N class token are treated as mentions, so ordinary links cannot be used to address notifications.
  2. Notifies each mentioned user plus any existing followers of the thread, with a short email linking back to the post (wp_send_note_notification()).
  3. Subscribes the note author and everyone they mention to the thread. Followers are stored as one _wp_note_followers meta row per user on the thread's top-level note - so concurrent replies cannot clobber each other - and the meta is registered for REST (editable by users who can edit_comment the note) so follower management UI can build on it.

Audience rules:

  • The post author is excluded - wp_new_comment_via_rest_notify_postauthor() already notifies them of every note.
  • The note's own author is never notified about their own note.
  • Recipients are limited to users who can edit_comment the note, matching WP_REST_Comments_Controller::check_read_permission() for notes, so emails cannot leak note content to users who cannot see the note in the editor.
  • Everything honors the existing wp_notes_notify option.

New filters: wp_note_notification_recipients, wp_note_notification_subject, wp_note_notification_text.

Why

Mentioning a collaborator in a note is only useful if they hear about it: the notification half closes that loop, and the follower model keeps everyone who has participated in a thread informed of later replies without requiring them to be re-mentioned.

This depends conceptually on the kses allowance in #12503: that is what lets the user-N mention class survive sanitization on a real REST write for users without unfiltered_html. The two are otherwise independent - no shared code paths - so they are reviewed and merged separately.

Testing

Unit tests in tests/phpunit/tests/comment/wpNotifyNoteMentions.php cover mention parsing (plain links ignored, IDs deduped), thread-root resolution, the mentioned-user email + auto-subscribe, author self-exclusion, post-author exclusion, capability gating (a mentioned subscriber is not emailed), follower-of-reply notification, the wp_notes_notify off switch, the recipients filter, follower removal, and the REST meta registration.

npm run test:php -- --group notes

Proposed commit message

Comments: Notify mentioned users and thread followers about new notes.

Port the notification layer from the Gutenberg Notes @mention work. On
rest_insert_comment for note comments, parse the user-N mention classes
out of the saved content, email each mentioned user plus any existing
followers of the thread, and subscribe the note author and everyone they
mention. Followers are stored as one _wp_note_followers meta row per user
on the thread's top-level note so concurrent replies cannot clobber each
other, and the meta is registered for REST so follower management UI can
build on it.

The post author is excluded because wp_new_comment_via_rest_notify_postauthor()
already notifies them of every note, the note's own author is never
notified about their own note, and recipients are limited to users who
can edit_comment the note so note content cannot leak. Everything honors
the wp_notes_notify option.

See related Gutenberg pull request: https://github.com/WordPress/gutenberg/pull/79606.

Props mamaduka.
Fixes #65639.

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

@github-actions

Copy link
Copy Markdown

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 adamsilverstein.

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

@github-actions

Copy link
Copy Markdown

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.

Port the notification layer from the Gutenberg Notes @mention work. On
rest_insert_comment for note comments, parse the user-N mention classes
out of the saved content, email each mentioned user plus any existing
followers of the thread, and subscribe the note author and everyone they
mention. Followers are stored as one _wp_note_followers meta row per user
on the thread's top-level note so concurrent replies cannot clobber each
other, and the meta is registered for REST so follower management UI can
build on it.

The post author is excluded because wp_new_comment_via_rest_notify_postauthor()
already notifies them of every note, the note's own author is never
notified about their own note, and recipients are limited to users who
can edit_comment the note so note content cannot leak. Everything honors
the wp_notes_notify option.

See related Gutenberg pull request: WordPress/gutenberg#79606.

Props mamaduka.
Fixes #65639.
@adamsilverstein adamsilverstein force-pushed the add/notes-mention-notifications branch from fc3e164 to 859ba08 Compare July 15, 2026 20:32
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.

1 participant