-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Notes unexpected do not notify post author (unlike comments) #10472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notes unexpected do not notify post author (unlike comments) #10472
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. |
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I installed the WP Mail SMTP plugin in my local environment, configured it with my personal Gmail SMTP server settings, and tested whether emails were actually being received.
The biggest concern is that adding a note takes a significant amount of time before the email sending process is actually completed. In my local environment, it took several seconds from pressing the "Add note" button until the snackbar appeared:
2a451d15c104aaead49a39947dab4d9f.mp4
I think it might be necessary to display some kind of loading indicator on the screen, or perhaps process the email sending using a cron job.
Another issue is that emails are also sent when a ticket is resolved or reopened, but there are two problems with this.
- It seems like I'm receiving multiple emails.
- Presumably, a different email content is needed for the approval/reopening action, because the "Note:" section will always be empty.
|
Maybe we can skip notifications when the note is empty? Good point about the delay when submitting a note, I was testing without actually sending the emails. I'll try a cron approach and use your testing approach. |
Note: requires cron be active for notifications to work
Co-authored-by: Aki Hamano <[email protected]>
I did this for now in f089d47 - I wonder if we should send a notification for "Thread resolved" or "Thread reopened" events.
I added a cron callback for the emails in cbfef88 - please give it another test @t-hamano |
@t-hamano, do you see performance difference with normal comments, when their notifications are sent? It might be an SMTP config that's adding those extra time. Usually, large installations will queue similar jobs in background and avoid adding overhead to the actual events. I think 10up popularized one of those libraries, back in a days :) P.S. I don't think core should tread |
|
I am fine reverting the cron approach, I was mostly exploring the idea. I also agree we shouldn't treat the code path differently than comments. Maybe this means comments should also use a cron approach, but that is a discussion for another day. |
There is no difference in performance. When sending normal comments, the browser loading time may be similarly long. However, the editor is reactive, and it feels very unnatural to me that the submitted note seems to disappear or that the snackbar appears with a delay. If we are sending emails in a conventional way, I would at least like to have some kind of loading indicator on the client side. |
I believe this also happens without the email if you are on a slow connection or have a very busy server - saving the note itself could take some time and currently there is no indicator of the process happening in the background. So to me this feels like an existing issue that is made more obvious by introducing a further processing delay (sending an email). |
This reverts commit cbfef88.
|
@desrosj note that the additional notification handling you've described is something I have stashed as a draft GitHub issue for 7.0, I'll make sure to tag you once I get that opened (frankly Monday earliest as I'm currently still sitting on the tarmac for last hour with travels this week 🥴 ) |
I added this in 887974e |
|
In quick testing, the additional setting for Notes emails in the Settings > Discussions menu appears as expected. Unfortunately I'm having trouble with Mailpit so I'm unable to validate the emails are firing as expected and have the format as expected. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've a added a few comments inline, nothing major.
In the message emailed to authors, I'm wondering if we should refer to it as an internal note or similar to better distinguish between a comment as someone scans their email. Naming things is hard so it's not a blocker and we can re-evaluate that at any time in the future without much work.
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
Outdated
Show resolved
Hide resolved
| /* translators: %s: Note author email. */ | ||
| $notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n"; | ||
| /* translators: %s: Note text. */ | ||
| $notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . ( empty( $comment_content ) ? __( 'resolved/reopened' ) : $comment_content ) ) . "\r\n\r\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to determine whether the status is resolved or reopened when empty? It's a little vague as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that should be doable based on comment meta or derived based on parent note status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meta is not yet saved at this hook, not sure the parent is helpful but I'll take a look.
| * | ||
| * @param WP_Comment $comment The comment object. | ||
| */ | ||
| public static function wp_new_comment_via_rest_notify_postauthor( $comment ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I wasn't able to find reasoning for moving this method here. So what was it?
IMO, seems odd and unrelated to have action callback in REST controller. It kind of goes against the idea of separation concerns. @TimothyBJacobs, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it in comments.php previously, but noticed some unit test failure because the hook was being fired in the test with a null comment. I can move it back and add a guard for this instead. I wasn't really sure about the best location for this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't the comment_post action execute when comments are posted through the REST API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s move it before RC so we don’t introduce accidental public function that we have to deprecate in next release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't the comment_post action execute when comments are posted through the REST API?
@ellatrix comment_post is triggered in wp_new_comment, but the REST controller never calls that - it calls wp_insert_comment directly. This triggers wp_insert_comment so we could hook there, it also fires rest_insert_comment slightly later which I decided was appropriate since I'm explicitly targeting the REST insertion with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
I confirmed that emails are only received when the ” Anyone posts a note” setting is enabled: |
|
How are we doing here? Code freeze for Beta 4 is in about an hour. Is this ready to go? |
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
I was waiting for feedback, I think we could commit this now and refine the few pieces of feedback later. |
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it again, and it's working as expected. This PR seems essential for Beta4, so let's commit it, and let's address any remaining feedback by RC1 if necessary.
| * | ||
| * @param WP_Comment $comment The comment object. | ||
| */ | ||
| public static function wp_new_comment_via_rest_notify_postauthor( $comment ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s move it before RC so we don’t introduce accidental public function that we have to deprecate in next release.
| // Send notifications for approved comments and all notes. | ||
| if ( | ||
| ! isset( $comment->comment_approved ) || | ||
| ( '1' !== $comment->comment_approved && ! $is_note ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it could be nice to have filters for this instead of hardcoded behavior for notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Yea, its a bit odd to have this logic here. There is a filter just above notify_post_author that can be used to opt out of notifications. The status and type should probably be used to set the default that is run thru that filter instead of being checked later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix an issue where new notes did not trigger a notification because they are submitted via the REST API. Ensures REST API submissions (for notes) trigger the post author notification. Leverage existing comment notification infrastructure. Developed in #10472. Fixes #64204. Props adamsilverstein, mamaduka, peterwilsoncc, ellatrix, wildworks, mukesh27, desrosj, annezazu, jeffpaul. git-svn-id: https://develop.svn.wordpress.org/trunk@61179 602fd350-edb4-49c9-b593-d223f7449a82
Fix an issue where new notes did not trigger a notification because they are submitted via the REST API. Ensures REST API submissions (for notes) trigger the post author notification. Leverage existing comment notification infrastructure. Developed in WordPress/wordpress-develop#10472. Fixes #64204. Props adamsilverstein, mamaduka, peterwilsoncc, ellatrix, wildworks, mukesh27, desrosj, annezazu, jeffpaul. Built from https://develop.svn.wordpress.org/trunk@61179 git-svn-id: http://core.svn.wordpress.org/trunk@60515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fix an issue where new notes did not trigger a notification because they are submitted via the REST API. Ensures REST API submissions (for notes) trigger the post author notification. Leverage existing comment notification infrastructure. Developed in WordPress/wordpress-develop#10472. Fixes #64204. Props adamsilverstein, mamaduka, peterwilsoncc, ellatrix, wildworks, mukesh27, desrosj, annezazu, jeffpaul. Built from https://develop.svn.wordpress.org/trunk@61179 git-svn-id: https://core.svn.wordpress.org/trunk@60515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Fix an issue where new notes did not trigger a notification because they are submitted via the REST API. Ensures REST API submissions (for notes) trigger the post author notification. Leverage existing comment notification infrastructure.
Testing instructions
Expected result
An email looks like this for a note "Leaving some feedback here." on a post entitled "Admin post":
Trac ticket: https://core.trac.wordpress.org/ticket/64204
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.