コメントなどの受信時に管理者宛に送られる承認待ちメールの内容を変更する
WordPressでは、管理画面の「設定」 > 「ディスカッション」にある「自分宛のメール通知」 > 「コメントがモデレーションのために保留されたとき」が有効な状態で承認が必要なコメントなどを受信した場合にはコメントやトラックバックを受信した時に「モデレートしてください」のような件名で管理者宛に承認メールが届きます。この件名や本文の内容を変更したい場合はテーマのfunctions.phpに下記のように記載します。
(コメント、トラックバック、ピンバックのすべての対応を行っているため少し長いコードになっています)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
/** * コメント確認メールの件名を変更します。 */ function custom_comment_moderation_subject( $subject, $comment_id ) { // ブログ名(サイト名) $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // コメント $comment = get_comment($comment_id); // 投稿 $post = get_post($comment->comment_post_ID); // トラックバック、ピンバック、コメントそれぞれで件名を変更 switch ( $comment->comment_type ) { case 'trackback': // トラックバック return "[{$blogname}] 「{$post->post_title}」にトラックバックがありました"; case 'pingback': // ピンバック return "[{$blogname}] 「{$post->post_title}」にピンバックがありました"; default: // コメント return "[{$blogname}] 「{$post->post_title}」にコメントがありました"; } } add_filter( 'comment_moderation_subject', 'custom_comment_moderation_subject', 10, 2 ); /** * コメント確認メールの本文を変更します。 */ 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 .= "========================================\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"; // 承認 $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 .= "未承認のコメント一覧(" . number_format_i18n($comments_waiting) . "件)を見る: \r\n"; $notify_message .= admin_url("edit-comments.php?comment_status=moderated") . "\r\n"; // === / 操作用URLの記載 === return $notify_message; } add_filter( 'comment_moderation_text', 'custom_comment_moderation_text', 10, 2 ); |
文面は好きなものに変更してください。
結果
コメントを受信した場合は下記のようなメールが届くようになります。