Comments: Notify mentioned users and thread followers for Notes @mentions#12548
Comments: Notify mentioned users and thread followers for Notes @mentions#12548adamsilverstein wants to merge 1 commit into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
fc3e164 to
859ba08
Compare
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).
What
On
rest_insert_commentfornotecomments (alongside the existing post-author notification),wp_notify_note_mentions():wp_get_note_mentioned_user_ids(): only anchors carrying both thewp-note-mentionclass and auser-Nclass token are treated as mentions, so ordinary links cannot be used to address notifications.wp_send_note_notification())._wp_note_followersmeta 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 canedit_commentthe note) so follower management UI can build on it.Audience rules:
wp_new_comment_via_rest_notify_postauthor()already notifies them of every note.edit_commentthe note, matchingWP_REST_Comments_Controller::check_read_permission()for notes, so emails cannot leak note content to users who cannot see the note in the editor.wp_notes_notifyoption.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-Nmention class survive sanitization on a real REST write for users withoutunfiltered_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.phpcover 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, thewp_notes_notifyoff switch, the recipients filter, follower removal, and the REST meta registration.Proposed commit message
Trac ticket: https://core.trac.wordpress.org/ticket/65639