WordPress.org

Make WordPress Core

Ticket #33717: 33717.8.diff

File 33717.8.diff, 4.8 KB (added by swissspidy, 6 years ago)
  • src/wp-includes/class-walker-comment.php

    diff --git src/wp-includes/class-walker-comment.php src/wp-includes/class-walker-comment.php
    index e0150b3..913d13f 100644
    class Walker_Comment extends Walker { 
    264264                        <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link( $comment ) ); ?>
    265265                </div>
    266266                <?php if ( '0' == $comment->comment_approved ) : ?>
    267                 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
     267                <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation. You will receive an email when it gets approved.' ) ?></em>
    268268                <br />
    269269                <?php endif; ?>
    270270
    class Walker_Comment extends Walker { 
    329329                                        </div><!-- .comment-metadata -->
    330330
    331331                                        <?php if ( '0' == $comment->comment_approved ) : ?>
    332                                         <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
     332                                        <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation. You will receive an email when it gets approved.' ); ?></p>
    333333                                        <?php endif; ?>
    334334                                </footer><!-- .comment-meta -->
    335335
  • src/wp-includes/comment-functions.php

    diff --git src/wp-includes/comment-functions.php src/wp-includes/comment-functions.php
    index 70a1bfd..728eb71 100644
    function wp_new_comment_notify_postauthor( $comment_ID ) { 
    16881688}
    16891689
    16901690/**
     1691 * Notify a comment author when their comment gets approved.
     1692 *
     1693 * This notification is only sent when the comment status
     1694 * changes from unapproved to approved.
     1695 *
     1696 * @since 4.4.0
     1697 *
     1698 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
     1699 * @return bool Whether the email was sent successfully.
     1700 */
     1701function wp_new_comment_notify_commenter( $comment_id ) {
     1702        $comment = get_comment( $comment_id );
     1703        if ( ! $comment ) {
     1704                return false;
     1705        }
     1706
     1707        $post           = get_post( $comment->comment_post_ID );
     1708        $comment_author = get_user_by( 'email', $comment->comment_author_email );
     1709
     1710        if ( ! $post ) {
     1711                return false;
     1712        }
     1713
     1714        // The comment was left by the post author.
     1715        if ( $comment->user_id === $post->post_author || $comment_author === get_userdata( $post->post_author ) ) {
     1716                return false;
     1717        }
     1718
     1719        if ( 1 === intval( get_comment_meta( $comment->comment_ID, '_wp_commenter_notification_sent', true ) ) ) {
     1720                return false;
     1721        }
     1722
     1723        /*
     1724         * The blogname option is escaped with esc_html
     1725         * on the way into the database in sanitize_option.
     1726         * We want to reverse this for the plain text arena of emails.
     1727         */
     1728        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     1729
     1730        /* translators: 1: blog name, 2: post title */
     1731        $subject = sprintf( __( '[%1$s] Your comment on "%2$s" got approved' ), $blogname, $post->post_title );
     1732
     1733        $notify_message = sprintf( __( 'Howdy %s,' ), $comment->comment_author ) . "\r\n\r\n";
     1734        $notify_message .= sprintf( __( 'Your comment on the post "%1$s" got approved.' ), $post->post_title ) . "\r\n\r\n";
     1735        /* translators: 1: comment author, 2: author IP, 3: author domain */
     1736        $notify_message .= sprintf( __( 'View comment: %s' ), get_comment_link( $comment ) ) . "\r\n";
     1737
     1738        /**
     1739         * Filter the comment approval notification email text.
     1740         *
     1741         * @since 4.4.0
     1742         *
     1743         * @param string     $notify_message The comment notification email text.
     1744         * @param WP_Comment $comment        Comment object.
     1745         */
     1746        $notify_message = apply_filters( 'comment_approval_notification_text', $notify_message, $comment );
     1747
     1748        /**
     1749         * Filter the comment approval notification email subject.
     1750         *
     1751         * @since 4.4.0
     1752         *
     1753         * @param string     $subject The comment notification email subject.
     1754         * @param WP_Comment $comment Comment object.
     1755         */
     1756        $subject = apply_filters( 'comment_approval_notification_subject', $subject, $comment );
     1757
     1758        $sent = wp_mail( $comment->comment_author_email, wp_specialchars_decode( $subject ), $notify_message );
     1759
     1760        update_comment_meta( $comment->comment_ID, '_wp_commenter_notification_sent', intval( $sent ) );
     1761
     1762        return $sent;
     1763}
     1764
     1765/**
    16911766 * Sets the status of a comment.
    16921767 *
    16931768 * The 'wp_set_comment_status' action is called after the comment is handled.
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index e9ddc47..f5f5926 100644
    add_action( 'comment_post', 'wp_new_comment_notify_postauthor' ); 
    342342add_action( 'after_password_reset', 'wp_password_change_notification' );
    343343add_action( 'register_new_user',      'wp_send_new_user_notifications' );
    344344add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
     345add_action( 'comment_unapproved_to_approved', 'wp_new_comment_notify_commenter' );
    345346
    346347/**
    347348 * Filters formerly mixed into wp-includes