Make WordPress Core

Ticket #25699: 25699.patch

File 25699.patch, 7.7 KB (added by ethitter, 11 years ago)
  • src/wp-includes/comment.php

     
    13761376 * that it is properly set, such as in wp-config.php, for your environment.
    13771377 * See {@link http://core.trac.wordpress.org/ticket/9235}
    13781378 *
    1379  * @since 1.5.0
    1380  * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing
    1381  * @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  * @param array $commentdata Contains information on the comment.
    1387  * @return int The ID of the comment after adding.
     1379 * @since  1.5.0
     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
     1390 * @return int                The ID of the comment after adding.
    13881391 */
    13891392function wp_new_comment( $commentdata ) {
    13901393        $commentdata = apply_filters('preprocess_comment', $commentdata);
     
    14171420                if ( '0' == $commentdata['comment_approved'] )
    14181421                        wp_notify_moderator($comment_ID);
    14191422
    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, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
    14241427        }
    14251428
    14261429        return $comment_ID;
  • src/wp-includes/pluggable.php

     
    10001000
    10011001if ( ! function_exists('wp_notify_postauthor') ) :
    10021002/**
    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 posts.
    10041004 *
    10051005 * @since 1.0.0
    10061006 *
    1007  * @param int $comment_id Comment ID
    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.
     1007 * @param  int $comment_id      Comment ID
     1008 * @param  string $comment_type Optional. The comment type either 'comment' (default), 'trackback', or 'pingback'
     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.
    10101020 */
    10111021function wp_notify_postauthor( $comment_id, $comment_type = '' ) {
    10121022        $comment = get_comment( $comment_id );
    1013         if ( empty( $comment ) )
     1023        if ( empty( $comment ) ) {
    10141024                return false;
     1025        }
    10151026
    10161027        $post    = get_post( $comment->comment_post_ID );
    10171028        $author  = get_userdata( $post->post_author );
    10181029
    1019         // The comment was left by the author
    1020         if ( $comment->user_id == $post->post_author )
     1030        // Who to notify? By default, just the post author, but others can be added.
     1031        $emails = array( $author->user_email );
     1032        $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id );
     1033        $emails = array_filter( $emails );
     1034
     1035        // If there are no addresses to send the comment to, bail.
     1036        if ( ! count( $emails ) ) {
    10211037                return false;
     1038        }
    10221039
     1040        // Facilitate unsetting below without knowing the keys.
     1041        $emails = array_flip( $emails );
     1042
     1043        // The comment was left by the author
     1044        if ( ! apply_filters( 'comment_notification_notify_author', false, $comment_id ) && $comment->user_id == $post->post_author ) {
     1045                unset( $emails[ $author->user_email ] );
     1046        }
     1047
    10231048        // The author moderated a comment on his own post
    1024         if ( $post->post_author == get_current_user_id() )
    1025                 return false;
     1049        if ( ! apply_filters( 'comment_notification_author_moderated', false, $comment_id ) && $post->post_author == get_current_user_id() ) {
     1050                unset( $emails[ $author->user_email ] );
     1051        }
    10261052
    10271053        // 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;
     1054        if ( ! apply_filters( 'comment_notification_notify_author_not_on_blog', false, $comment_id ) && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
     1055                unset( $emails[ $author->user_email ] );
     1056        }
    10301057
    1031         // If there's no email to send the comment to
    1032         if ( '' == $author->user_email )
     1058        // If there's no email to send the comment to, bail, otherwise flip array back around for use below
     1059        if ( ! count( $emails ) ) {
    10331060                return false;
     1061        } else {
     1062                $emails = array_flip( $emails );
     1063        }
    10341064
    10351065        $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
    10361066
     
    10381068        // we want to reverse this for the plain text arena of emails.
    10391069        $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    10401070
    1041         if ( empty( $comment_type ) ) $comment_type = 'comment';
     1071        if ( empty( $comment_type ) ) {
     1072                $comment_type = 'comment';
     1073        }
    10421074
    10431075        switch ( $comment_type ) {
    10441076                case 'trackback':
     
    10781110        $notify_message .= sprintf( __('Permalink: %s'), get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ) . "\r\n";
    10791111
    10801112        if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) {
    1081                 if ( EMPTY_TRASH_DAYS )
     1113                if ( EMPTY_TRASH_DAYS ) {
    10821114                        $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
    1083                 else
     1115                } else {
    10841116                        $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
     1117                }
     1118
    10851119                $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
    10861120        }
    10871121
     
    10891123
    10901124        if ( '' == $comment->comment_author ) {
    10911125                $from = "From: \"$blogname\" <$wp_email>";
    1092                 if ( '' != $comment->comment_author_email )
     1126                if ( '' != $comment->comment_author_email ) {
    10931127                        $reply_to = "Reply-To: $comment->comment_author_email";
     1128                }
    10941129        } else {
    10951130                $from = "From: \"$comment->comment_author\" <$wp_email>";
    1096                 if ( '' != $comment->comment_author_email )
     1131                if ( '' != $comment->comment_author_email ) {
    10971132                        $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
     1133                }
    10981134        }
    10991135
    11001136        $message_headers = "$from\n"
    11011137                . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    11021138
    1103         if ( isset($reply_to) )
     1139        if ( isset( $reply_to ) ) {
    11041140                $message_headers .= $reply_to . "\n";
     1141        }
    11051142
    1106         $emails = array( $author->user_email );
    1107 
    1108         $emails          = apply_filters( 'comment_notification_recipients', $emails,          $comment_id );
    11091143        $notify_message  = apply_filters( 'comment_notification_text',       $notify_message,  $comment_id );
    11101144        $subject         = apply_filters( 'comment_notification_subject',    $subject,         $comment_id );
    11111145        $message_headers = apply_filters( 'comment_notification_headers',    $message_headers, $comment_id );