Skip to content

Comments: Only email the post author when a note is created. - #16369

Open
adamsilverstein wants to merge 3 commits into
WordPress:trunkfrom
adamsilverstein:trac-66891/note-edit-email
Open

adamsilverstein wants to merge 3 commits into
WordPress:trunkfrom
adamsilverstein:trac-66891/note-edit-email

Conversation

@adamsilverstein

Copy link
Copy Markdown
Member

Claude Code (Opus 5.5) reproduced this in the editor, then wrote the fix and tests:

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

wp_new_comment_via_rest_notify_postauthor() runs on rest_insert_comment, which fires for both creates and updates. It never looked at the action's $creating argument, so every edit to a note sent the post author the "new note" email again.

The callback now accepts the $request and $creating arguments, returns early on updates, and is registered with three accepted arguments. This matches wp_notify_note_mentions() on the same hook. Direct callers that pass only the comment keep the old behavior, since $creating defaults to true.

Reproduction

The new e2e spec (tests/e2e/specs/notes-notifications.test.js) logs in as admin, adds a note to a post written by another user, edits the note through the notes UI, and counts the emails sent to the post author. A must-use plugin records only mail addressed to that test's author, so other workers are not affected.

On trunk, the spec fails with two identical emails:

Error: should not email the post author again when the note is edited
Expected length: 1
Received length: 2
Received array:  ["[WordPress Develop] Note: \"Post with a note f6c9...\"", "[WordPress Develop] Note: \"Post with a note f6c9...\""]

With the fix it passes, including three repeats in the parallel project.

Changes

  • Return early from wp_new_comment_via_rest_notify_postauthor() when $creating is false.
  • Register the callback with three accepted arguments.
  • Add PHPUnit tests for the create (notifies) and update (does not notify) REST requests. The update test fails on trunk.
  • Add the e2e spec described above.

Testing

  • npm run test:php -- --filter Tests_Comment_WpNewCommentViaRestNotifyPostauthor
  • npm run test:php -- --group notes,comment (936 tests pass) and --filter WP_Test_REST_Comments_Controller (302 tests pass)
  • npm run test:e2e -- tests/e2e/specs/notes-notifications.test.js
  • Manual: as a user other than the post author, add a note to a post, then edit it. The post author gets one email, not two.

AI Use

Claude Code (Opus 5.5) wrote the fix, both sets of tests, and this description. I will review and test.

🤖 Generated with Claude Code

https://claude.ai/code/session_018vwYjTtzMQnfuAJYcpNH6Z

adamsilverstein and others added 2 commits December 1, 2026 11:45
Editing a note through the REST API sends the post author the "new note" email again, because wp_new_comment_via_rest_notify_postauthor() runs on every rest_insert_comment, creates and updates alike. These tests fail until that is fixed: the e2e spec adds and edits a note in the editor and counts the emails the post author gets, and the PHPUnit tests cover the create and update requests directly.

See #66891.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vwYjTtzMQnfuAJYcpNH6Z
rest_insert_comment fires for both creates and updates, and the post author callback ignored its $creating argument, so each edit to a note re-sent the "new note" email. The callback now takes the action's three arguments and returns early on updates, matching wp_notify_note_mentions() on the same hook. Direct callers that pass only the comment keep the old behavior, since $creating defaults to true.

Fixes #66891.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vwYjTtzMQnfuAJYcpNH6Z
@github-actions

github-actions Bot commented Dec 1, 2026

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.

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.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Dec 1, 2026

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.

Declares `$creating` as a native bool, matching wp_notify_note_mentions() on the same hook, so a non-boolean value cannot slip past the update check. The `$request` docblock now allows its null default.

See #66891.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vwYjTtzMQnfuAJYcpNH6Z
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