OOL Limit Comments to IPs

This plugin is designed to stop non-local users from posting comments.  We live in a island community which participates in lots of discussion.  I tire of tossing out all the spam comments that have nothing to do with the community in our archipelago. I have hacked WP to stop all comments from outside our local IPs blocks form commenting on the site.  Now to tun it into a plugin. My 1st as it were.

Version 0.1 – not a plugin state.

I added the following code to  wp-includes/comments.php at line 563

// Added by Rick Boucher @ Orcas Online
// Define acceptable ip addresses
$acceptableip=array('69.7.32','207.178.21','72.167.35');

// Check the guestip against good list
foreach ($acceptableip as $i => $value) {
 if (strstr($comment_author_IP,$value)) {
 $goodguestip=1;
 }
 }
// if the guestip is not good toss em to wp_die screen
if ($goodguestip != "1") {     
 wp_die( __('Sorry only comments from those local to our area allowed.') );
 }
// end add

Of course knowing two things.

1) as soon as I upgrade WP the comments.php file gets changed.

2) The ips “not blocked” from commenting would change/ be expanded to include more geo-locals.

Next version…..Create a basic plugin

Go over to http://codex.wordpress.org/Writing_a_Plugin and get going on a basic WP plugin.

Using BBEDIT – I set up the Plugin Header and GPL License. I researched “hooks” at http://codex.wordpress.org/Plugin_API and found Adam Brown’s WP Hooks Database to be very helpful in deciding which filter/action to hook into.  Decided on “pre_comment_content” for now.

Saved the file and found it needed to be a zipped file.  Saw other plugins with folders to made a folder with my name “oollimitcomments2ips” and zipped it and uploaded.  Wow it worked!!!

But where was it??  It was on the server but not on the list. OK so maybe the folder idea was a nada.  So I zipped the file and uploaded that. No go. Headers were bad. Hmmmm.  Looked aat code and found some “comments” from examples left there.  Deleted and tried again.

Wow something was wrong.  It uploaded and showed on the list (Yippee!), but the title showed other junk which messed with the admin layout. I determined that BBEDIT was saving the file with Macintosh linebreaks. Re-saved with unix linebreaks. and …

Voila!! It was there and looked like it would work.

Now to test……  It activated …… Well lots to think about here.  Got it to work in the end.  Apparently variables are not passed to functions unless they are tossed at em. Duh!  And I added a “return;” but not sure I need it will test again.

BUT it worked.  Changed the IP critieria and it caught me and stopped me. Need to to test that some more.  But it looks like it worked.