最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

notifications - How can I edit the email sent when a new comment is received?

programmeradmin3浏览0评论

I have a multi author site and when a user comments on a post, that author gets an email saying there is a new comment. This email is formated in the standard WordPress way

New comment on your post "Test post for comment testing"
Author : Person (IP: 0.0.0.0 , netowrk) E-mail : [email protected]
URL    : 
Whois  : 
Comment: 
Test

You can see all comments on this post here: 


Permalink: 

The site doesn't utilize URLs in the comment field so this is always blank. I'd also like to remove WHOIS and IP and network details, leaving the commenters name and email.

How can I edit this? Preferably without a plugin if possible.

I have a multi author site and when a user comments on a post, that author gets an email saying there is a new comment. This email is formated in the standard WordPress way

New comment on your post "Test post for comment testing"
Author : Person (IP: 0.0.0.0 , netowrk) E-mail : [email protected]
URL    : 
Whois  : 
Comment: 
Test

You can see all comments on this post here: 
http://example/test-post

Permalink: http://example/test-post

The site doesn't utilize URLs in the comment field so this is always blank. I'd also like to remove WHOIS and IP and network details, leaving the commenters name and email.

How can I edit this? Preferably without a plugin if possible.

Share Improve this question asked Dec 2, 2014 at 23:16 user37474user37474 2
  • 1 What have you actually tried, you need to hook into comment_notification_text – Wyck Commented Dec 2, 2014 at 23:47
  • @Wyck I haven't tried anything because I have absolutely no idea where to look and all my Googling has resulted in unrelated results. But now I know to look into comment_notification_text some more. Ta. – user37474 Commented Dec 2, 2014 at 23:58
Add a comment  | 

1 Answer 1

Reset to default 4

The comment_notification_text filter is in wp-includes/pluggable.php in the wp_notify_postauthor function. You can copy and paste the $notify_message stuff and edit out what you don't want.

function wpd_comment_notification_text( $notify_message, $comment_id ){
    // get the current comment and post data
    $comment = get_comment( $comment_id );
    $post = get_post( $comment->comment_post_ID );
    // don't modify trackbacks or pingbacks
    if( '' == $comment->comment_type ){
        // build the new message text
        $notify_message  = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
        $notify_message .= sprintf( __('Author : %1$s'), $comment->comment_author ) . "\r\n";
        $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
        $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "\r\n";
        $notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
        $notify_message .= __('You can see all comments on this post here: ') . "\r\n";
        $notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
        $notify_message .= sprintf( __('Permalink: %s'), get_comment_link( $comment_id ) ) . "\r\n";

        if ( user_can( $post->post_author, 'edit_comment', $comment_id ) ) {
            if ( EMPTY_TRASH_DAYS )
                $notify_message .= sprintf( __('Trash it: %s'), admin_url("comment.php?action=trash&c=$comment_id") ) . "\r\n";
            else
                $notify_message .= sprintf( __('Delete it: %s'), admin_url("comment.php?action=delete&c=$comment_id") ) . "\r\n";
            $notify_message .= sprintf( __('Spam it: %s'), admin_url("comment.php?action=spam&c=$comment_id") ) . "\r\n";
        }
    }
    // return the notification text
    return $notify_message;
}
add_filter( 'comment_notification_text', 'wpd_comment_notification_text', 20, 2 );
发布评论

评论列表(0)

  1. 暂无评论