Skip to content

Commit 8ec209c

Browse files
Send a notification to the post author when a note is added
1 parent be6a610 commit 8ec209c

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/wp-includes/comment.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,8 +2448,10 @@ function wp_new_comment_notify_postauthor( $comment_id ) {
24482448
}
24492449

24502450
// Only send notifications for approved comments.
2451-
if ( ! isset( $comment->comment_approved ) || '1' !== $comment->comment_approved ) {
2452-
return false;
2451+
if (
2452+
! isset( $comment->comment_approved ) ||
2453+
( '1' !== $comment->comment_approved && 'note' !== $comment->comment_type ) ) {
2454+
return false;
24532455
}
24542456

24552457
return wp_notify_postauthor( $comment_id );

src/wp-includes/default-filters.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@
522522
// Email notifications.
523523
add_action( 'comment_post', 'wp_new_comment_notify_moderator' );
524524
add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
525+
add_action( 'rest_insert_comment', function( $comment ) {
526+
if ( 'note' === $comment->comment_type ) {
527+
wp_new_comment_notify_postauthor( $comment->comment_ID );
528+
}
529+
} );
525530
add_action( 'after_password_reset', 'wp_password_change_notification' );
526531
add_action( 'register_new_user', 'wp_send_new_user_notifications' );
527532
add_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );

src/wp-includes/pluggable.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,20 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
18941894
$subject = sprintf( __( '[%1$s] Pingback: "%2$s"' ), $blogname, $post->post_title );
18951895
break;
18961896

1897+
case 'note':
1898+
/* translators: %s: Post title. */
1899+
$notify_message = sprintf( __( 'New note on your post "%s"' ), $post->post_title ) . "\r\n";
1900+
/* translators: 1: Note author's name, 2: Note author's IP address, 3: Note author's hostname. */
1901+
$notify_message .= sprintf( __( 'Author: %1$s (IP address: %2$s, %3$s)' ), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
1902+
/* translators: %s: Note author email. */
1903+
$notify_message .= sprintf( __( 'Email: %s' ), $comment->comment_author_email ) . "\r\n";
1904+
/* translators: %s: Note text. */
1905+
$notify_message .= sprintf( __( 'Note: %s' ), "\r\n" . $comment_content ) . "\r\n\r\n";
1906+
$notify_message .= __( 'You can see all notes on this post here:' ) . "\r\n";
1907+
/* translators: Note notification email subject. 1: Site title, 2: Post title. */
1908+
$subject = sprintf( __( '[%1$s] Note: "%2$s"' ), $blogname, $post->post_title );
1909+
break;
1910+
18971911
default: // Comments.
18981912
/* translators: %s: Post title. */
18991913
$notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
@@ -1917,11 +1931,15 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) {
19171931
break;
19181932
}
19191933

1920-
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
19211934
/* translators: %s: Comment URL. */
1922-
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
1935+
if ( 'note' === $comment->comment_type ) {
1936+
$notify_message .= admin_url( "post.php?post={$comment->comment_post_ID}" ) . "\r\n";
1937+
} else {
1938+
$notify_message .= get_permalink( $comment->comment_post_ID ) . "#comments\r\n\r\n";
1939+
$notify_message .= sprintf( __( 'Permalink: %s' ), get_comment_link( $comment ) ) . "\r\n";
1940+
}
19231941

1924-
if ( user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
1942+
if ( 'note' !== $comment->comment_type && user_can( $post->post_author, 'edit_comment', $comment->comment_ID ) ) {
19251943
if ( EMPTY_TRASH_DAYS ) {
19261944
/* translators: Comment moderation. %s: Comment action URL. */
19271945
$notify_message .= sprintf( __( 'Trash it: %s' ), admin_url( "comment.php?action=trash&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n";

0 commit comments

Comments
 (0)