From c6148497863615de1b968fa4331518d3302640d0 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 14 Sep 2015 02:17:26 +0000 Subject: [PATCH] Send comment notification emails via a hooked function. Previously, `wp_notify_postauthor()` and `wp_notify_moderator()` were called directly from `wp_new_comment()`, making it difficult to modify or suppress default notification emails. Props dshanske, thomaswm. See #33587. Built from https://develop.svn.wordpress.org/trunk@34106 git-svn-id: http://core.svn.wordpress.org/trunk@34074 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-functions.php | 45 ++++++++++++++++++++++--------- wp-includes/default-filters.php | 4 +++ wp-includes/version.php | 2 +- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index f953a9e102..8a65a46d4c 100644 --- a/wp-includes/comment-functions.php +++ b/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/wp-includes/default-filters.php b/wp-includes/default-filters.php index b6f0ce303e..8ce3660f43 100644 --- a/wp-includes/default-filters.php +++ b/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 */ diff --git a/wp-includes/version.php b/wp-includes/version.php index 686e154f7b..aba5c055d2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34105'; +$wp_version = '4.4-alpha-34106'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.