diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index f953a9e102..8a65a46d4c 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -1629,21 +1629,42 @@ function wp_new_comment( $commentdata ) { */ do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'] ); - if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching - if ( '0' == $commentdata['comment_approved'] ) { - wp_notify_moderator( $comment_ID ); - } - - // wp_notify_postauthor() checks if notifying the author of their own comment. - // By default, it won't, but filters can override this. - if ( get_option( 'comments_notify' ) && $commentdata['comment_approved'] ) { - wp_notify_postauthor( $comment_ID ); - } - } - return $comment_ID; } +/** + * Send a comment moderation notification to the comment moderator. + * + * @since 4.4.0 + * + * @param int $comment_ID ID of the comment. + * @param int $comment_approved Whether the comment is approved. + */ +function wp_new_comment_notify_moderator( $comment_ID, $comment_approved ) { + if ( '0' == $comment_approved ) { + wp_notify_moderator( $comment_ID ); + } +} + +/** + * Send a notification of a new comment to the post author. + * + * @since 4.4.0 + * + * @param int $comment_ID ID of the comment. + */ +function wp_new_comment_notify_postauthor( $comment_ID ) { + $comment = get_comment( $comment_ID ); + + /* + * `wp_notify_postauthor()` checks if notifying the author of their own comment. + * By default, it won't, but filters can override this. + */ + if ( get_option( 'comments_notify' ) && $comment->comment_approved ) { + wp_notify_postauthor( $comment_ID ); + } +} + /** * Sets the status of a comment. * diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index b6f0ce303e..8ce3660f43 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -334,6 +334,10 @@ add_action( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 ); add_action( 'split_shared_term', '_wp_check_split_nav_menu_terms', 10, 4 ); add_action( 'wp_split_shared_term_batch', '_wp_batch_split_terms' ); +// Email notifications. +add_action( 'comment_post', 'wp_new_comment_notify_moderator', 10, 2 ); +add_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); + /** * Filters formerly mixed into wp-includes */