WordPress.org

Make WordPress Core

Ticket #761: 761.3.diff

File 761.3.diff, 2.6 KB (added by coffee2code, 6 years ago)

Minimal change to introduce filter (and not touch the pluggable wp_notify_postauthor())

  • wp-includes/comment.php

     
    13321332 *
    13331333 * @since 1.5.0
    13341334 * @uses apply_filters() Calls 'preprocess_comment' hook on $commentdata parameter array before processing
     1335 * @uses apply_filters() Calls 'wp_notify_post_author' hook on initial evaluation about if post author should be notified and comment ID.
    13351336 * @uses do_action() Calls 'comment_post' hook on $comment_ID returned from adding the comment and if the comment was approved.
    13361337 * @uses wp_filter_comment() Used to filter comment before adding comment.
    13371338 * @uses wp_allow_comment() checks to see if comment is approved.
     
    13731374
    13741375                $post = get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
    13751376
    1376                 if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
     1377                $maybe_notify = get_option( 'comments_notify' ) && $commentdata['comment_approved'];
     1378                if ( isset( $commentdata['user_id'] ) && $post->post_author == $commentdata['user_id'] )
     1379                    $maybe_notify = false;
     1380                $maybe_notify = apply_filters( 'wp_notify_post_author', $maybe_notify, $comment_ID );
     1381
     1382                if ( $maybe_notify )
    13771383                        wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
    13781384        }
    13791385
     
    13881394 *
    13891395 * @since 1.0.0
    13901396 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
     1397 * @uses apply_filters() Calls 'wp_notify_post_author' hook on initial evaluation about if post author should be notified and comment ID.
    13911398 *
    13921399 * @param int $comment_id Comment ID.
    13931400 * @param string $comment_status New comment status, either 'hold', 'approve', 'spam', or 'trash'.
     
    14061413                case 'approve':
    14071414                case '1':
    14081415                        $status = '1';
    1409                         if ( get_option('comments_notify') ) {
    1410                                 $comment = get_comment($comment_id);
    1411                                 wp_notify_postauthor($comment_id, $comment->comment_type);
    1412                         }
    14131416                        break;
    14141417                case 'spam':
    14151418                        $status = 'spam';
     
    14341437
    14351438        $comment = get_comment($comment_id);
    14361439
     1440        $maybe_notify = get_option( 'comments_notify' ) && '1' == $status;
     1441        $maybe_notify = apply_filters( 'wp_notify_post_author', $maybe_notify, $comment_id );
     1442        if ( $maybe_notify )
     1443                wp_notify_postauthor( $comment_id, $comment->comment_type );
     1444
    14371445        do_action('wp_set_comment_status', $comment_id, $comment_status);
    14381446        wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment);
    14391447