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