<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26367] trunk/src/wp-includes: Fix `comment_notification_recipients` filter behavior so that it is still respected even on comments left by the post author</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26367">26367</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-11-25 01:46:49 +0000 (Mon, 25 Nov 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix `comment_notification_recipients` filter behavior so that it is still respected even on comments left by the post author
The code was bailing on this-is-a-comment-on-your-own-post detection, ignoring additional recipients. Now:
* Logic check is done within `wp_notify_postauthor()`
* Logic check is overridable via `comment_notification_notify_author` filter (default still false)
* The code doesn't bail on comment-on-own-post detection, but just removes the author from the array
* The code instead now bails if the recipients list is empty, so `comment_notification_recipients` works properly
props ethitter.
fixes <a href="http://core.trac.wordpress.org/ticket/25699">#25699</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescommentphp">trunk/src/wp-includes/comment.php</a></li>
<li><a href="#trunksrcwpincludespluggablephp">trunk/src/wp-includes/pluggable.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescommentphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/comment.php (26366 => 26367)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/comment.php 2013-11-24 22:06:13 UTC (rev 26366)
+++ trunk/src/wp-includes/comment.php 2013-11-25 01:46:49 UTC (rev 26367)
</span><span class="lines">@@ -1377,13 +1377,16 @@
</span><span class="cx"> * See {@link http://core.trac.wordpress.org/ticket/9235}
</span><span class="cx"> *
</span><span class="cx"> * @since 1.5.0
</span><del>- * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing
- * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.
- * @uses wp_filter_comment() Used to filter comment before adding comment.
- * @uses wp_allow_comment() checks to see if comment is approved.
- * @uses wp_insert_comment() Does the actual comment insertion to the database.
- *
</del><span class="cx"> * @param array $commentdata Contains information on the comment.
</span><ins>+ * @uses apply_filters()
+ * @uses wp_get_comment_status()
+ * @uses wp_filter_comment()
+ * @uses wp_allow_comment()
+ * @uses wp_insert_comment()
+ * @uses do_action()
+ * @uses wp_notify_moderator()
+ * @uses get_option()
+ * @uses wp_notify_postauthor()
</ins><span class="cx"> * @return int The ID of the comment after adding.
</span><span class="cx"> */
</span><span class="cx"> function wp_new_comment( $commentdata ) {
</span><span class="lines">@@ -1418,12 +1421,10 @@
</span><span class="cx"> wp_notify_moderator( $comment_ID );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( get_option('comments_notify') && $commentdata['comment_approved'] ) {
- $post = get_post( $commentdata['comment_post_ID'] );
- // Don't notify if it's your own comment
- if ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) {
- wp_notify_postauthor( $comment_ID );
- }
</del><ins>+ // 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 );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1457,7 +1458,7 @@
</span><span class="cx"> case '1':
</span><span class="cx"> $status = '1';
</span><span class="cx"> if ( get_option('comments_notify') ) {
</span><del>- wp_notify_postauthor( $comment_id );
</del><ins>+ wp_notify_postauthor( $comment_id );
</ins><span class="cx"> }
</span><span class="cx"> break;
</span><span class="cx"> case 'spam':
</span></span></pre></div>
<a id="trunksrcwpincludespluggablephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/pluggable.php (26366 => 26367)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/pluggable.php 2013-11-24 22:06:13 UTC (rev 26366)
+++ trunk/src/wp-includes/pluggable.php 2013-11-25 01:46:49 UTC (rev 26367)
</span><span class="lines">@@ -1000,13 +1000,23 @@
</span><span class="cx">
</span><span class="cx"> if ( ! function_exists('wp_notify_postauthor') ) :
</span><span class="cx"> /**
</span><del>- * Notify an author of a comment/trackback/pingback to one of their posts.
</del><ins>+ * Notify an author (and/or others) of a comment/trackback/pingback on a post.
</ins><span class="cx"> *
</span><span class="cx"> * @since 1.0.0
</span><span class="cx"> *
</span><span class="cx"> * @param int $comment_id Comment ID
</span><span class="cx"> * @param string $deprecated Not used
</span><del>- * @return bool False if user email does not exist. True on completion.
</del><ins>+ * @uses get_comment()
+ * @uses get_post()
+ * @uses get_userdata()
+ * @uses apply_filters()
+ * @uses wp_specialchars_decode()
+ * @uses get_option()
+ * @uses __()
+ * @uses get_permalink()
+ * @uses admin_url()
+ * @uses wp_mail()
+ * @return bool True on completion. False if no email addresses were specified.
</ins><span class="cx"> */
</span><span class="cx"> function wp_notify_postauthor( $comment_id, $deprecated = null ) {
</span><span class="cx"> if ( null !== $deprecated ) {
</span><span class="lines">@@ -1020,21 +1030,43 @@
</span><span class="cx"> $post = get_post( $comment->comment_post_ID );
</span><span class="cx"> $author = get_userdata( $post->post_author );
</span><span class="cx">
</span><del>- // The comment was left by the author
- if ( $comment->user_id == $post->post_author )
- return false;
</del><ins>+ // Who to notify? By default, just the post author, but others can be added.
+ $emails = array( $author->user_email );
+ $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
+ $emails = array_filter( $emails );
</ins><span class="cx">
</span><del>- // The author moderated a comment on his own post
- if ( $post->post_author == get_current_user_id() )
</del><ins>+ // If there are no addresses to send the comment to, bail.
+ if ( ! count( $emails ) ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx">
</span><ins>+ // Facilitate unsetting below without knowing the keys.
+ $emails = array_flip( $emails );
+
+ // Post author may want to receive notifications for their own comments
+ $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id );
+
+ // The comment was left by the author
+ if ( ! $notify_author && $comment->user_id == $post->post_author ) {
+ unset( $emails[ $author->user_email ] );
+ }
+
+ // The author moderated a comment on their own post
+ if ( ! $notify_author && $post->post_author == get_current_user_id() ) {
+ unset( $emails[ $author->user_email ] );
+ }
+
</ins><span class="cx"> // The post author is no longer a member of the blog
</span><del>- if ( ! user_can( $post->post_author, 'read_post', $post->ID ) )
- return false;
</del><ins>+ if ( ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
+ unset( $emails[ $author->user_email ] );
+ }
</ins><span class="cx">
</span><del>- // If there's no email to send the comment to
- if ( '' == $author->user_email )
</del><ins>+ // If there's no email to send the comment to, bail, otherwise flip array back around for use below
+ if ( ! count( $emails ) ) {
</ins><span class="cx"> return false;
</span><ins>+ } else {
+ $emails = array_flip( $emails );
+ }
</ins><span class="cx">
</span><span class="cx"> $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
</span><span class="cx">
</span><span class="lines">@@ -1042,9 +1074,7 @@
</span><span class="cx"> // we want to reverse this for the plain text arena of emails.
</span><span class="cx"> $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
</span><span class="cx">
</span><del>- $comment_type = $comment->comment_type ? $comment->comment_type : 'comment';
-
- switch ( $comment_type ) {
</del><ins>+ switch ( $comment->comment_type ) {
</ins><span class="cx"> case 'trackback':
</span><span class="cx"> $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n";
</span><span class="cx"> /* translators: 1: website name, 2: author IP, 3: author domain */
</span><span class="lines">@@ -1107,9 +1137,6 @@
</span><span class="cx"> if ( isset($reply_to) )
</span><span class="cx"> $message_headers .= $reply_to . "\n";
</span><span class="cx">
</span><del>- $emails = array( $author->user_email );
-
- $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
</del><span class="cx"> $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id );
</span><span class="cx"> $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id );
</span><span class="cx"> $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );
</span></span></pre>
</div>
</div>
</body>
</html>