Make WordPress Core

Changeset 34106


Ignore:
Timestamp:
09/14/2015 02:16:02 AM (9 years ago)
Author:
boonebgorges
Message:

Send comment notification emails via a hooked function.

Previously, wp_notify_postauthor() and wp_notify_moderator() were called
directly from wp_new_comment(), making it difficult to modify or suppress
default notification emails.

Props dshanske, thomaswm.
See #33587.

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

Legend:

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

    r33964 r34106  
    16301630    do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'] );
    16311631
    1632     if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
    1633         if ( '0' == $commentdata['comment_approved'] ) {
    1634             wp_notify_moderator( $comment_ID );
    1635         }
    1636 
    1637         // wp_notify_postauthor() checks if notifying the author of their own comment.
    1638         // By default, it won't, but filters can override this.
    1639         if ( get_option( 'comments_notify' ) && $commentdata['comment_approved'] ) {
    1640             wp_notify_postauthor( $comment_ID );
    1641         }
    1642     }
    1643 
    16441632    return $comment_ID;
     1633}
     1634
     1635/**
     1636 * Send a comment moderation notification to the comment moderator.
     1637 *
     1638 * @since 4.4.0
     1639 *
     1640 * @param int $comment_ID       ID of the comment.
     1641 * @param int $comment_approved Whether the comment is approved.
     1642 */
     1643function wp_new_comment_notify_moderator( $comment_ID, $comment_approved ) {
     1644    if ( '0' == $comment_approved ) {
     1645        wp_notify_moderator( $comment_ID );
     1646    }
     1647}
     1648
     1649/**
     1650 * Send a notification of a new comment to the post author.
     1651 *
     1652 * @since 4.4.0
     1653 *
     1654 * @param int $comment_ID ID of the comment.
     1655 */
     1656function wp_new_comment_notify_postauthor( $comment_ID ) {
     1657    $comment = get_comment( $comment_ID );
     1658
     1659    /*
     1660     * `wp_notify_postauthor()` checks if notifying the author of their own comment.
     1661     * By default, it won't, but filters can override this.
     1662     */
     1663    if ( get_option( 'comments_notify' ) && $comment->comment_approved ) {
     1664        wp_notify_postauthor( $comment_ID );
     1665    }
    16451666}
    16461667
  • trunk/src/wp-includes/default-filters.php

    r33615 r34106  
    335335add_action( 'wp_split_shared_term_batch', '_wp_batch_split_terms' );
    336336
     337// Email notifications.
     338add_action( 'comment_post', 'wp_new_comment_notify_moderator', 10, 2 );
     339add_action( 'comment_post', 'wp_new_comment_notify_postauthor' );
     340
    337341/**
    338342 * Filters formerly mixed into wp-includes
Note: See TracChangeset for help on using the changeset viewer.