WordPress.org

Make WordPress Core

Changeset 26367


Ignore:
Timestamp:
11/25/13 01:46:49 (5 months ago)
Author:
markjaquith
Message:

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 #25699

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r26358 r26367  
    13781378 * 
    13791379 * @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  * 
    13861380 * @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() 
    13871390 * @return int The ID of the comment after adding. 
    13881391 */ 
     
    14191422        } 
    14201423 
    1421         if ( get_option('comments_notify') && $commentdata['comment_approved'] ) { 
    1422             $post = get_post( $commentdata['comment_post_ID'] ); 
    1423             // Don't notify if it's your own comment 
    1424             if ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) { 
    1425                 wp_notify_postauthor( $comment_ID ); 
    1426             } 
     1424        // wp_notify_postauthor() checks if notifying the author of their own comment. 
     1425        // By default, it won't, but filters can override this. 
     1426        if ( get_option( 'comments_notify' ) && $commentdata['comment_approved'] ) { 
     1427            wp_notify_postauthor( $comment_ID ); 
    14271428        } 
    14281429    } 
     
    14581459            $status = '1'; 
    14591460            if ( get_option('comments_notify') ) { 
    1460                 wp_notify_postauthor( $comment_id );  
     1461                wp_notify_postauthor( $comment_id ); 
    14611462            } 
    14621463            break; 
  • trunk/src/wp-includes/pluggable.php

    r26358 r26367  
    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 post. 
    10041004 * 
    10051005 * @since 1.0.0 
     
    10071007 * @param int $comment_id Comment ID 
    10081008 * @param string $deprecated Not used 
    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. 
    10101020 */ 
    10111021function wp_notify_postauthor( $comment_id, $deprecated = null ) { 
     
    10211031    $author  = get_userdata( $post->post_author ); 
    10221032 
     1033    // Who to notify? By default, just the post author, but others can be added. 
     1034    $emails = array( $author->user_email ); 
     1035    $emails = apply_filters( 'comment_notification_recipients', $emails, $comment_id ); 
     1036    $emails = array_filter( $emails ); 
     1037 
     1038    // If there are no addresses to send the comment to, bail. 
     1039    if ( ! count( $emails ) ) { 
     1040        return false; 
     1041    } 
     1042 
     1043    // Facilitate unsetting below without knowing the keys. 
     1044    $emails = array_flip( $emails ); 
     1045 
     1046    // Post author may want to receive notifications for their own comments 
     1047    $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment_id ); 
     1048 
    10231049    // The comment was left by the author 
    1024     if ( $comment->user_id == $post->post_author ) 
     1050    if ( ! $notify_author && $comment->user_id == $post->post_author ) { 
     1051        unset( $emails[ $author->user_email ] ); 
     1052    } 
     1053 
     1054    // The author moderated a comment on their own post 
     1055    if ( ! $notify_author && $post->post_author == get_current_user_id() ) { 
     1056        unset( $emails[ $author->user_email ] ); 
     1057    } 
     1058 
     1059    // The post author is no longer a member of the blog 
     1060    if ( ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { 
     1061        unset( $emails[ $author->user_email ] ); 
     1062    } 
     1063 
     1064    // If there's no email to send the comment to, bail, otherwise flip array back around for use below 
     1065    if ( ! count( $emails ) ) { 
    10251066        return false; 
    1026  
    1027     // The author moderated a comment on his own post 
    1028     if ( $post->post_author == get_current_user_id() ) 
    1029         return false; 
    1030  
    1031     // The post author is no longer a member of the blog 
    1032     if ( ! user_can( $post->post_author, 'read_post', $post->ID ) ) 
    1033         return false; 
    1034  
    1035     // If there's no email to send the comment to 
    1036     if ( '' == $author->user_email ) 
    1037         return false; 
     1067    } else { 
     1068        $emails = array_flip( $emails ); 
     1069    } 
    10381070 
    10391071    $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 
     
    10431075    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
    10441076 
    1045     $comment_type = $comment->comment_type ? $comment->comment_type : 'comment';  
    1046  
    1047     switch ( $comment_type ) { 
     1077    switch ( $comment->comment_type ) { 
    10481078        case 'trackback': 
    10491079            $notify_message  = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; 
     
    11081138        $message_headers .= $reply_to . "\n"; 
    11091139 
    1110     $emails = array( $author->user_email ); 
    1111  
    1112     $emails          = apply_filters( 'comment_notification_recipients', $emails,          $comment_id ); 
    11131140    $notify_message  = apply_filters( 'comment_notification_text',       $notify_message,  $comment_id ); 
    11141141    $subject         = apply_filters( 'comment_notification_subject',    $subject,         $comment_id ); 
Note: See TracChangeset for help on using the changeset viewer.