コメント通知のメール本文を変更する
コメントやトラックバックがついた時に送信されるメールの本文を変更します。
※参考にさせて頂きました。
WordPressカスタマイズ辞典
//コメント確認メールの本文を変更
function custom_comment_text( $notify_message, $comment_id) {
// コメント情報
$comment = get_comment($comment_id);
// コメントのあった投稿
$post = get_post($comment->comment_post_ID);
// 投稿元のドメイン名
$comment_author_domain = @gethostbyaddr($comment->comment_author_IP);
// ブログ名(サイト名)
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
// コメント
$comment_content = wp_specialchars_decode($comment->comment_content);
//コメントの承認状態
$comment_approved = ($comment->comment_approved);
// トラックバック、ピンバック、コメントそれぞれで本文を変更
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 .= "========================================\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";
$notify_message .= "========================================\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 .= "========================================\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";
$notify_message .= "========================================\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 .= "========================================\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";
$notify_message .= "========================================\r\n";
$notify_message .= "\r\n";
break;
}
//ここから操作用URLの記載
$notify_message .= "各操作は下記のアドレスから行うことができます。\r\n";
$notify_message .= "\r\n";
if($comment_approved != '1'){
// 承認
$notify_message .= "承認: \r\n";
$notify_message .= admin_url("comment.php?action=approve&c=$comment_id") . "\r\n";
}
if ( EMPTY_TRASH_DAYS ) {
// ゴミ箱に移動
$notify_message .= "ゴミ箱に移動: \r\n";
$notify_message .= admin_url("comment.php?action=trash&c=$comment_id") . "\r\n";
}else{
// 削除
$notify_message .= "削除: \r\n";
$notify_message .= admin_url("comment.php?action=delete&c=$comment_id") . "\r\n";
}
// スパムとしてマーク
$notify_message .= "スパムとしてマーク: \r\n";
$notify_message .= admin_url("comment.php?action=spam&c=$comment_id") . "\r\n";
// 未承認のコメント一覧
$notify_message .= "未承認のコメント一覧:\r\n";
$notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n";
return $notify_message;
}
//コメントの承認待ちメール
add_filter('comment_moderation_text', 'custom_comment_text', 10, 2 );
//コメントの通知メール
add_filter('comment_notification_text', 'custom_comment_text', 10, 2);※参考にさせて頂きました。
WordPressカスタマイズ辞典
RECENT POSTS
SEARCH





