[CODE] Integrating the spam filter into WordPress

Mods for various forums/blogs for use with the SBST

Moderator: fspamlist

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

[CODE] Integrating the spam filter into WordPress

Postby MysteryFCM » Wed Dec 10, 2008 2:27 pm

I've only checked this with WordPress 2.6.5, but it should work with the rest.

Open wp_comments-post.php

Find: (approx line #39)

Code: Select all

$comment_author       = trim(strip_tags($_POST['author']));
$comment_author_email = trim($_POST['email']);
$comment_author_url   = trim($_POST['url']);
$comment_content      = trim($_POST['comment']);


Add AFTER

Code: Select all

// BEGIN SPAM MOD
   $ip = $_SERVER['REMOTE_ADDR'];
   $fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$comment_author.'&email='.$comment_author_email.'&ip='.$ip);
   if (strpos($fspamcheck, 'TRUE') !==False) {
      // Notify admin via e-mail
      $blockedby = str_replace(' TRUE', '', $fspamcheck);
      $blockedby = str_replace(' ', ' & ', $blockedby);
      $msg = 'The following was blocked by the '.$blockedby.' filter<br><br>Username: '.$comment_author.'<br><br>Email: '.$comment_author_email.'<br><br>IP: '.$ip;
      // Change your@email.addr to the e-mail address you want e-mail reports sent to
      $to = "your@email.addr";
      $from = "nobody@".$_SERVER['SERVER_NAME'];
      $subject = "Spammer blocked by hpHosts Spam filter";
      $headers =    "MIME-Versin: 1.0\r\n" .
      "Content-type: text/html; charset=ISO-8859-1; format=flowed\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n" .
      "From: " . $from . "\r\n" .
      "X-Mailer: hpHosts Spam Filter";
      mail($to, $subject, $msg, $headers);
      // Notify user
       wp_die( __('Your comment has been blocked by our <a href="http://temerc.com/Check_Spammers/">spam filter</a>. Please either try again or contact an administrator') );
   }
   // END SPAM MOD


Or alternatively, if you'd rather not play with actual code, Xaviermedia.com have developed a plugin to better integrate the SBST for Wordpress.

http://www.xaviermedia.com/php/wp-check-spammers.php
Last edited by MysteryFCM on Sat Jan 30, 2010 8:31 pm, edited 5 times in total.
Reason: Corrected code (changed return/die() to wp_die) and made slight modification (move $ip to save repetition)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into WordPress

Postby MysteryFCM » Wed Dec 10, 2008 10:51 pm

Tested with 2.7 (just released) and works perfectly :)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into WordPress

Postby MysteryFCM » Wed Jan 07, 2009 5:35 pm

To block them registering aswell;

Open wp-login.php

Find: (Approx line #206)

Code: Select all

   // Check the username


Add BEFORE

Code: Select all

// BEGIN SPAM MOD
   $ip = $_SERVER['REMOTE_ADDR'];
   $fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$user_login.'&email='.$user_email.'&ip='.$ip);
   if (strpos($fspamcheck, 'TRUE') !==False) {
      // Notify admin via e-mail
      $blockedby = str_replace(' TRUE', '', $fspamcheck);
      $blockedby = str_replace(' ', ' & ', $blockedby);
      $msg = 'The following was blocked by the '.$blockedby.' filter<br><br>Username: '.$user_login.'<br><br>Email: '.$user_email.'<br><br>IP: '.$ip;
      // Change your@email.addr to the e-mail address you want e-mail reports sent to
      $to = "your@email.addr";
      $from = "nobody@".$_SERVER['SERVER_NAME'];
      $subject = "Spammer blocked by hpHosts Spam filter";
      $headers =    "MIME-Versin: 1.0\r\n" .
      "Content-type: text/html; charset=ISO-8859-1; format=flowed\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n" .
      "From: " . $from . "\r\n" .
      "X-Mailer: hpHosts Spam Filter";
      mail($to, $subject, $msg, $headers);
      // Notify user
      $errors->add('reg_blocked', __('<strong>ERROR</strong>: Your registration has been blocked by our <a href="http://temerc.com/Check_Spammers/">spam filter</a>. Please either try again or contact an administrator'));
   }
   // END SPAM MOD
Last edited by MysteryFCM on Thu May 14, 2009 2:01 pm, edited 2 times in total.
Reason: Corrected code
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into WordPress

Postby MysteryFCM » Fri Sep 25, 2009 3:34 pm

If your host does not allow file_get_contents(), you will need to change this call from;

Code: Select all

$fspamcheck = file_get_contents('http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$comment_author.'&email='.$comment_author_email.'&ip='.$ip);


To;

Code: Select all

$curl = @curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://temerc.com/Check_Spammers/check_spammers_plain.php?name='.$comment_author.'&email='.$comment_author_email.'&ip='.$ip);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$fspamcheck = @curl_exec($curl);
curl_close($curl);
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!

User avatar
bylla
Posts: 1
Joined: Sun Jan 03, 2010 11:40 am
Contact:

Re: [CODE] Integrating the spam filter into WordPress

Postby bylla » Fri Jan 22, 2010 12:13 pm

The downside by editing the code of Wordpress is that every time you upgrade Wordpress you need to edit the code again, so I wrote a plugin instead. That way you can activate the code from the admin dashboard and also use a settings page to set your email address etc.

The plugin is available from http://www.xaviermedia.com/php/wp-check-spammers.php

/Bylla

User avatar
MysteryFCM
Site Admin
Site Admin
Posts: 3721
Joined: Sun May 15, 2005 12:42 pm
Location: Newcastle, UK
Contact:

Re: [CODE] Integrating the spam filter into WordPress

Postby MysteryFCM » Fri Jan 22, 2010 12:24 pm

Nice one, cheers for letting me know :)
Regards

Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net

Keeping it FREE!


Return to “Mods”

Who is online

Users browsing this forum: No registered users and 1 guest