WordPress.org

Make WordPress Core

Ticket #33717: 33717.7.diff

File 33717.7.diff, 4.7 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 50d6d36..fe00616 100644
    function wp_new_comment_notify_postauthor( $comment_ID ) { 
    16881688}
    16891689
    16901690/**
     1691 * Notify a comment author when his 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 WP_Comment $comment Comment object.
     1699 *
     1700 * @return bool Whether the email was sent successfully.
     1701 */
     1702function wp_new_comment_notify_commenter( $comment ) {
     1703        $post           = get_post( $comment->comment_post_ID );
     1704        $comment_author = get_user_by( 'email', $comment->comment_author_email );
     1705
     1706        if ( ! $post ) {
     1707                return false;
     1708        }
     1709
     1710        // The comment was left by the post author.
     1711        if ( $comment->user_id === $post->post_author || $comment_author === get_userdata( $post->post_author ) ) {
     1712                return false;
     1713        }
     1714
     1715        if ( 1 === intval( get_comment_meta( $comment->comment_ID, '_wp_notification_sent', true ) ) ) {
     1716                return false;
     1717        }
     1718
     1719        /*
     1720         * The blogname option is escaped with esc_html
     1721         * on the way into the database in sanitize_option.
     1722         * We want to reverse this for the plain text arena of emails.
     1723         */
     1724        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     1725
     1726        /* translators: 1: blog name, 2: post title */
     1727        $subject = sprintf( __( '[%1$s] Your comment on "%2$s" got approved' ), $blogname, $post->post_title );
     1728
     1729        $notify_message = sprintf( __( 'Howdy %s,' ), $comment->comment_author ) . "\r\n\r\n";
     1730        $notify_message .= sprintf( __( 'Your comment on the post "%1$s" got approved.' ), $post->post_title ) . "\r\n\r\n";
     1731        /* translators: 1: comment author, 2: author IP, 3: author domain */
     1732        $notify_message .= sprintf( __( 'View comment: %s' ), get_comment_link( $comment ) ) . "\r\n";
     1733
     1734        /**
     1735         * Filter the comment approval notification email text.
     1736         *
     1737         * @since 4.4.0
     1738         *
     1739         * @param string     $notify_message The comment notification email text.
     1740         * @param WP_Comment $comment        Comment object.
     1741         */
     1742        $notify_message = apply_filters( 'comment_approval_notification_text', $notify_message, $comment );
     1743
     1744        /**
     1745         * Filter the comment approval notification email subject.
     1746         *
     1747         * @since 4.4.0
     1748         *
     1749         * @param string     $subject The comment notification email subject.
     1750         * @param WP_Comment $comment Comment object.
     1751         */
     1752        $subject = apply_filters( 'comment_approval_notification_subject', $subject, $comment );
     1753
     1754        $sent = wp_mail( $comment->comment_author_email, wp_specialchars_decode( $subject ), $notify_message );
     1755
     1756        update_comment_meta( $comment->comment_ID, '_wp_notification_sent', intval( $sent ) );
     1757
     1758        return $sent;
     1759}
     1760
     1761/**
    16911762 * Sets the status of a comment.
    16921763 *
    16931764 * 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