WPでコメントからくるメールのテンプレートについて
少し疑問がでたのですが、
第三者が投稿のコメント欄にコメントを
入れると下記のメールがとどきました。
メールの内容を変更したく
下記のコードをfunctions.phpに
書いたのですのが表示が
変わることがありませんでした。
何が原因なのでしょうか。
ご教授お願いします。
WordPressのバージョン
WordPress 4.6.5
メール内容
宛先:nihon@japan.site
返信先:ajia@japan.site
投稿 "今日のご飯" に新しいコメントがありました
投稿者: nihon1 (IP: 000.000.000.000, ai123456789123.46.access-internet.ne.jp)
メールアドレス: ajia@japan.site
URL:
コメント:
美味しいですね(^_^;)
この投稿へのすべてのコメントはこちらです:
http://◯◯◯◯◯◯.net
パーマリンク: http://◯◯◯◯◯◯.net
ゴミ箱に移動する: http://◯◯◯◯◯◯.net
スパムとしてマークする: http://◯◯◯◯◯◯.net
試したコード
php
1/** 2 * コメント確認メールの件名を変更します。 3 */ 4function custom_comment_moderation_subject( $subject, $comment_id ) { 5 // ブログ名(サイト名) 6 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 7 // コメント 8 $comment = get_comment($comment_id); 9 // 投稿 10 $post = get_post($comment->comment_post_ID); 11 // トラックバック、ピンバック、コメントそれぞれで件名を変更 12 switch ( $comment->comment_type ) { 13 case 'trackback': // トラックバック 14 return "[{$blogname}] 「{$post->post_title}」にトラックバックがありました"; 15 case 'pingback': // ピンバック 16 return "[{$blogname}] 「{$post->post_title}」にピンバックがありました"; 17 default: // コメント 18 return "[{$blogname}] 「{$post->post_title}」にコメントがありました"; 19 } 20} 21add_filter( 'comment_moderation_subject', 'custom_comment_moderation_subject', 10, 2 ); 22 23/** 24 * コメント確認メールの本文を変更します。 25 */ 26function custom_comment_moderation_text( $notify_message, $comment_id ) { 27 global $wpdb; 28 // コメント 29 $comment = get_comment($comment_id); 30 // コメントのあった投稿 31 $post = get_post($comment->comment_post_ID); 32 // 投稿元のドメイン名 33 $comment_author_domain = @gethostbyaddr($comment->comment_author_IP); 34 // 未承認の数を取得 35 $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'"); 36 // ブログ名(サイト名) 37 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 38 // コメント 39 $comment_content = wp_specialchars_decode( $comment->comment_content ); 40 41 // トラックバック、ピンバック、コメントそれぞれで本文を変更 42 switch ( $comment->comment_type ) { 43 case 'trackback': // トラックバック 44 $notify_message = "「{$post->post_title}」にトラックバックがありました。確認をお願いします。\r\n"; 45 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 46 $notify_message .= "\r\n"; 47 $notify_message .= "========================================\r\n"; 48 $notify_message .= "\r\n"; 49 $notify_message .= "トラックバック元: {$comment->comment_author}\r\n"; 50 $notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n"; 51 $notify_message .= "URL: {$comment->comment_author_url}\r\n"; 52 $notify_message .= "トラックバックの概要: \r\n"; 53 $notify_message .= "{$comment_content}\r\n"; 54 $notify_message .= "\r\n"; 55 $notify_message .= "========================================\r\n"; 56 $notify_message .= "\r\n"; 57 break; 58 case 'pingback': // ピンバック 59 $notify_message = "「{$post->post_title}」にピンバックがありました。確認をお願いします。\r\n"; 60 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 61 $notify_message .= "\r\n"; 62 $notify_message .= "========================================\r\n"; 63 $notify_message .= "\r\n"; 64 $notify_message .= "ピンバック元: {$comment->comment_author}\r\n"; 65 $notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n"; 66 $notify_message .= "URL: {$comment->comment_author_url}\r\n"; 67 $notify_message .= "ピンバックの概要: \r\n"; 68 $notify_message .= "{$comment_content}\r\n"; 69 $notify_message .= "\r\n"; 70 $notify_message .= "========================================\r\n"; 71 $notify_message .= "\r\n"; 72 break; 73 default: // コメント 74 $notify_message = "「{$post->post_title}」にコメントがありました。確認をお願いします。\r\n"; 75 $notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n"; 76 $notify_message .= "\r\n"; 77 $notify_message .= "========================================\r\n"; 78 $notify_message .= "\r\n"; 79 $notify_message .= "投稿者: {$comment->comment_author}\r\n"; 80 $notify_message .= "IP: {$comment->comment_author_IP} ({$comment_author_domain})\r\n"; 81 $notify_message .= "メールアドレス: {$comment->comment_author_email}\r\n"; 82 $notify_message .= "URL: {$comment->comment_author_url}\r\n"; 83 $notify_message .= "コメント: \r\n"; 84 $notify_message .= "{$comment_content}\r\n"; 85 $notify_message .= "\r\n"; 86 $notify_message .= "========================================\r\n"; 87 $notify_message .= "\r\n"; 88 break; 89 } 90 91 92 // === 操作用URLの記載 === 93 94 $notify_message .= "各操作は下記のアドレスから行うことができます。\r\n"; 95 $notify_message .= "\r\n"; 96 97 // 承認 98 $notify_message .= "承認: \r\n"; 99 $notify_message .= admin_url("comment.php?action=approve&c=$comment_id") . "\r\n"; 100 // ゴミ箱に移動 101 if ( EMPTY_TRASH_DAYS ) { 102 $notify_message .= "ゴミ箱に移動: \r\n"; 103 $notify_message .= admin_url("comment.php?action=trash&c=$comment_id") . "\r\n"; 104 } 105 // 削除 106 else { 107 $notify_message .= "削除: \r\n"; 108 $notify_message .= admin_url("comment.php?action=delete&c=$comment_id") . "\r\n"; 109 } 110 // スパムとしてマーク 111 $notify_message .= "スパムとしてマーク: \r\n"; 112 $notify_message .= admin_url("comment.php?action=spam&c=$comment_id") . "\r\n"; 113 // 未承認のコメント一覧 114 $notify_message .= "未承認のコメント一覧(" . number_format_i18n($comments_waiting) . "件)を見る: \r\n"; 115 $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; 116 117 // === / 操作用URLの記載 === 118 119 return $notify_message; 120} 121add_filter( 'comment_moderation_text', 'custom_comment_moderation_text', 10, 2 );
こうなると思った
「◯◯◯◯」にコメントがありました。確認をお願いします。
http://◯◯◯◯◯
========================================
投稿者:◯◯◯◯◯
IP:000.0000.0000.0
メールアドレス:◯◯◯◯◯@◯◯◯◯◯
URL:http://◯◯◯◯◯
コメント:
◯◯◯◯◯
========================================
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/25 13:38
2017/04/25 14:35
2017/04/26 02:03
2017/04/26 03:00
2017/04/26 03:54
2017/04/26 08:26