Ticket #25699: 25699.4.patch
File 25699.4.patch, 5.9 KB (added by , 11 years ago) |
---|
-
src/wp-includes/comment.php
1377 1377 * See {@link http://core.trac.wordpress.org/ticket/9235} 1378 1378 * 1379 1379 * @since 1.5.0 1380 * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing1381 * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.1382 * @uses wp_filter_comment() Used to filter comment before adding comment.1383 * @uses wp_allow_comment() checks to see if comment is approved.1384 * @uses wp_insert_comment() Does the actual comment insertion to the database.1385 *1386 1380 * @param array $commentdata Contains information on the comment. 1381 * @uses apply_filters() 1382 * @uses wp_get_comment_status() 1383 * @uses wp_filter_comment() 1384 * @uses wp_allow_comment() 1385 * @uses wp_insert_comment() 1386 * @uses do_action() 1387 * @uses wp_notify_moderator() 1388 * @uses get_option() 1389 * @uses wp_notify_postauthor() 1387 1390 * @return int The ID of the comment after adding. 1388 1391 */ 1389 1392 function wp_new_comment( $commentdata ) { … … 1417 1420 if ( '0' == $commentdata['comment_approved'] ) 1418 1421 wp_notify_moderator($comment_ID); 1419 1422 1420 $post = get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment 1421 1422 if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) ) 1423 wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' ); 1423 // wp_notify_postauthor() checks if notifying the author of his/her own comment. 1424 // By default, it won't, but filters can override this. 1425 if ( get_option( 'comments_notify' ) && $commentdata['comment_approved'] ) { 1426 wp_notify_postauthor( $comment_ID ); 1427 } 1424 1428 } 1425 1429 1426 1430 return $comment_ID; -
src/wp-includes/pluggable.php
1000 1000 1001 1001 if ( ! function_exists('wp_notify_postauthor') ) : 1002 1002 /** 1003 * Notify an author of a comment/trackback/pingback to one of their posts.1003 * Notify an author (and/or others) of a comment/trackback/pingback on a post. 1004 1004 * 1005 1005 * @since 1.0.0 1006 1006 * 1007 1007 * @param int $comment_id Comment ID 1008 1008 * @param string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback' 1009 * @return bool False if user email does not exist. True on completion. 1009 * @uses get_comment() 1010 * @uses get_post() 1011 * @uses get_userdata() 1012 * @uses apply_filters() 1013 * @uses wp_specialchars_decode() 1014 * @uses get_option() 1015 * @uses __() 1016 * @uses get_permalink() 1017 * @uses admin_url() 1018 * @uses wp_mail() 1019 * @return bool True on completion. False if no email addresses were specified. 1010 1020 */ 1011 1021 function wp_notify_postauthor( $comment_id, $comment_type = '' ) { 1012 1022 $comment = get_comment( $comment_id ); … … 1016 1026 $post = get_post( $comment->comment_post_ID ); 1017 1027 $author = get_userdata( $post->post_author ); 1018 1028 1019 // The comment was left by the author 1020 if ( $comment->user_id == $post->post_author ) 1029 // Who to notify? By default, just the post author, but others can be added. 1030 $emails = array( $author->user_email ); 1031 $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id ); 1032 $emails = array_filter( $emails ); 1033 1034 // If there are no addresses to send the comment to, bail. 1035 if ( ! count( $emails ) ) { 1021 1036 return false; 1037 } 1022 1038 1039 // Facilitate unsetting below without knowing the keys. 1040 $emails = array_flip( $emails ); 1041 1042 // Post author may want to receive notifications for their own comments 1043 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); 1044 1045 // The comment was left by the author 1046 if ( ! $notify_author && $comment->user_id == $post->post_author ) { 1047 unset( $emails[ $author->user_email ] ); 1048 } 1049 1023 1050 // The author moderated a comment on his own post 1024 if ( $post->post_author == get_current_user_id() ) 1025 return false; 1051 if ( ! $notify_author && $post->post_author == get_current_user_id() ) { 1052 unset( $emails[ $author->user_email ] ); 1053 } 1026 1054 1027 1055 // The post author is no longer a member of the blog 1028 if ( ! user_can( $post->post_author, 'read_post', $post->ID ) ) 1029 return false; 1056 if ( ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { 1057 unset( $emails[ $author->user_email ] ); 1058 } 1030 1059 1031 // If there's no email to send the comment to 1032 if ( '' == $author->user_email )1060 // If there's no email to send the comment to, bail, otherwise flip array back around for use below 1061 if ( ! count( $emails ) ) { 1033 1062 return false; 1063 } else { 1064 $emails = array_flip( $emails ); 1065 } 1034 1066 1035 1067 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 1036 1068 … … 1038 1070 // we want to reverse this for the plain text arena of emails. 1039 1071 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 1040 1072 1041 if ( empty( $comment_type ) ) $comment_type = 'comment'; 1042 1043 switch ( $comment_type ) { 1073 switch ( $comment->comment_type ) { 1044 1074 case 'trackback': 1045 1075 $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; 1046 1076 /* translators: 1: website name, 2: author IP, 3: author domain */ … … 1103 1133 if ( isset($reply_to) ) 1104 1134 $message_headers .= $reply_to . "\n"; 1105 1135 1106 $emails = array( $author->user_email );1107 1108 $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );1109 1136 $notify_message = apply_filters( 'comment_notification_text', $notify_message, $comment_id ); 1110 1137 $subject = apply_filters( 'comment_notification_subject', $subject, $comment_id ); 1111 1138 $message_headers = apply_filters( 'comment_notification_headers', $message_headers, $comment_id );