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.

git-svn-id: https://develop.svn.wordpress.org/trunk@34106 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
boonebgorges 2015-09-14 02:16:02 +00:00
parent a620cd1e34
commit 05d4233956
2 changed files with 37 additions and 12 deletions

View File

@ -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.
*

View File

@ -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
*/