トラックバック、ピンバック、コメントの通知メール内容を変更
WordPressのSNSプラグイン、BuddyPressを導入すると不特定多数のメンバーが参加することになる。
コメントがついた時に、投稿者にコメントが来たという通知メールが届く。
そこにIPアドレスが表示されたり、著者のURLや、コメントを書いた人のメールアドレスが表示される。
投稿者にIPメールアドレスなどは知らせる必要はないのでこれを削除したい。
ということで、メールの内容変更する。
  
functions.php へ記述
そこにIPアドレスが表示されたり、著者のURLや、コメントを書いた人のメールアドレスが表示される。
投稿者にIPメールアドレスなどは知らせる必要はないのでこれを削除したい。
// トラックバック、ピンバック、コメントの通知メールの内容を変更する
function custom_comment_moderation_text( $notify_message, $comment_id ) {
 global $wpdb;
 $comment = get_comment($comment_id);
 $post = get_post($comment->comment_post_ID);
 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 $comment_content = wp_specialchars_decode( $comment->comment_content );
 switch ( $comment->comment_type ) {
  case 'trackback': // トラックバック
  $notify_message = "「{$post->post_title}」に新しいトラックバックがありました。\r\n";
  $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  $notify_message .= "\r\n";
  $notify_message .= "トラックバック元: {$comment->comment_author}\r\n";
  //$notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n";
  //$notify_message .= "URL: {$comment->comment_author_url}\r\n";
  $notify_message .= "トラックバックの概要: \r\n";
  $notify_message .= "{$comment_content}\r\n";
  $notify_message .= "\r\n";
  break;
 case 'pingback': // ピンバック
  $notify_message = "「{$post->post_title}」に新しいピンバックがありました。\r\n";
  $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  $notify_message .= "\r\n";
  $notify_message .= "ピンバック元: {$comment->comment_author}\r\n";
  //$notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n";
  //$notify_message .= "URL: {$comment->comment_author_url}\r\n";
  $notify_message .= "ピンバックの概要: \r\n";
  $notify_message .= "{$comment_content}\r\n";
  $notify_message .= "\r\n";
  break;
 default: // コメント
  $notify_message = "「{$post->post_title}」に新しいコメントがありました。\r\n";
  $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
  $notify_message .= "\r\n";
  $notify_message .= "投稿者: {$comment->comment_author}\r\n";
  //$notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n";
  //$notify_message .= "メールアドレス: {$comment->comment_author_email}\r\n";
  //$notify_message .= "URL: {$comment->comment_author_url}\r\n";
  $notify_message .= "コメント: \r\n";
  $notify_message .= "{$comment_content}\r\n";
  $notify_message .= "\r\n";
  break;
 }
 return $notify_message;
}
add_filter( 'comment_moderation_text', 'custom_comment_moderation_text', 10, 2 );
add_filter( 'comment_notification_text', 'custom_comment_moderation_text', 10, 2 );これで、コメント承認通知メールと、コメントがつけられた時の通知メールの、内容を変更してIPアドレスなどを表示しないようにする。
しかし、実は、問題があり、
 通知メールに「返信」した時には、コメントをくれた人のメールアドレスへの返信となってしまう。
メールヘッダーに reply-to 要素に、コメントを書いた人のメールアドレスが入っているからだ。
これを変更するには下記関連記事の、メールに返信した時にコメントを書いた人のメールアドレスが出ないようにする を参照。
