| | 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 | */ |
| | 1702 | function 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 | /** |