注文の多いXOOPS屋 TOP現在のブログ旧スタッフblog アーカイブ
このページは 2007〜2008 年に公開していた「株式会社RYUS スタッフblog」のアーカイブです。内容は当時のものです。

wordpress で スパムコメントは、メール通知しないようにする

2007/05/18 14:43   Ryuji   カテゴリ: wordpress

SOMY SpamBlock JP プラグインを使うようになってから、海外からのスパム削除に追われることが減ったのですが、一点だけちょっと面倒だと感じたことがあります。

それは、スパム判定したら自動削除という設定にしているにもかかわらず、コメント投稿通知のメールが送られてくる点です。

本家の wordpress では大丈夫なのかもしれませんが、XOOPS モジュール版の wordpress では、メール通知後にプラグインが呼ばれるため、プラグインだけでは、メール通知をとめることができません。

しかしプログラム中のある 1 行を移動するだけでプラグインの呼び出しをメール通知前に変更できます。

wordpress/wp-comments-post.php の 100 行目あたりに次のようなコードがあります。

	$comment_ID = $wpdb->get_var('SELECT last_insert_id()');

if (($moderation_notify) && (!$approved)) {
wp_notify_moderator($comment_ID);
}

if ((get_settings('comments_notify')) && ($approved)) {
wp_notify_postauthor($comment_ID, 'comment');
}

if ($email == '')
$email = ' '; // this to make sure a cookie is set for 'no email'

if ($url == '')
$url = ' '; // this to make sure a cookie is set for 'no url'

do_action('comment_post', $comment_ID);/PRE

最後にある do_action の行を、移動させて下記のようにします。

	$comment_ID = $wpdb->get_var('SELECT last_insert_id()');

do_action('comment_post', $comment_ID);

if (($moderation_notify) && (!$approved)) {
wp_notify_moderator($comment_ID);
}

if ((get_settings('comments_notify')) && ($approved)) {
wp_notify_postauthor($comment_ID, 'comment');
}

if ($email == '')
$email = ' '; // this to make sure a cookie is set for 'no email'

if ($url == '')
$url = ' '; // this to make sure a cookie is set for 'no url'/PRE

これでスパム判定されたらメール通知も無しで削除されるようになりました。

スパムコメントの通知メールでメーラーの受信トレイがいっぱいになるという、ちょっと笑えない状態になってましたが、これで解放されました(笑